Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from transformers import DPTFeatureExtractor, DPTForDepthEstimation
|
|
| 3 |
from diffusers import StableDiffusionPipeline
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
| 6 |
-
import cv2
|
| 7 |
from PIL import Image, ImageEnhance
|
| 8 |
import open3d as o3d
|
| 9 |
|
|
@@ -22,12 +22,26 @@ feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
|
| 22 |
depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 23 |
|
| 24 |
def enhance_depth_map(depth_map):
|
| 25 |
-
""" Apply filters to enhance depth details """
|
| 26 |
-
depth_map = cv2.GaussianBlur(depth_map, (5, 5), 0) # Smooth the depth map
|
| 27 |
-
depth_map = cv2.bilateralFilter(depth_map, 9, 75, 75) # Preserve edges
|
| 28 |
-
depth_map = cv2.convertScaleAbs(depth_map, alpha=1.2, beta=10) # Increase contrast
|
| 29 |
-
depth_map = cv2.Laplacian(depth_map, cv2.CV_8U) # Sharpen details
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def generate_3d_from_text(prompt):
|
| 33 |
# Step 1: Generate Image from Text Prompt
|
|
|
|
| 3 |
from diffusers import StableDiffusionPipeline
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
| 6 |
+
# import cv2
|
| 7 |
from PIL import Image, ImageEnhance
|
| 8 |
import open3d as o3d
|
| 9 |
|
|
|
|
| 22 |
depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 23 |
|
| 24 |
def enhance_depth_map(depth_map):
|
| 25 |
+
# """ Apply filters to enhance depth details """
|
| 26 |
+
# depth_map = cv2.GaussianBlur(depth_map, (5, 5), 0) # Smooth the depth map
|
| 27 |
+
# depth_map = cv2.bilateralFilter(depth_map, 9, 75, 75) # Preserve edges
|
| 28 |
+
# depth_map = cv2.convertScaleAbs(depth_map, alpha=1.2, beta=10) # Increase contrast
|
| 29 |
+
# depth_map = cv2.Laplacian(depth_map, cv2.CV_8U) # Sharpen details
|
| 30 |
+
|
| 31 |
+
""" Apply alternative filters to enhance depth details without OpenCV """
|
| 32 |
+
depth_image_pil = Image.fromarray(depth_map)
|
| 33 |
+
|
| 34 |
+
# Increase contrast
|
| 35 |
+
enhancer = ImageEnhance.Contrast(depth_image_pil)
|
| 36 |
+
depth_image_pil = enhancer.enhance(1.5)
|
| 37 |
+
|
| 38 |
+
# Sharpen the depth map
|
| 39 |
+
enhancer = ImageEnhance.Sharpness(depth_image_pil)
|
| 40 |
+
depth_image_pil = enhancer.enhance(2.0)
|
| 41 |
+
|
| 42 |
+
return np.array(depth_image_pil)
|
| 43 |
+
|
| 44 |
+
# return depth_map
|
| 45 |
|
| 46 |
def generate_3d_from_text(prompt):
|
| 47 |
# Step 1: Generate Image from Text Prompt
|