Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -237,9 +237,30 @@ class RetroArtConverter:
|
|
| 237 |
def get_depth_map(self, image):
|
| 238 |
"""Generate depth map using Zoe Depth"""
|
| 239 |
if self.zoe_depth is not None:
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
else:
|
| 244 |
# Fallback to simple grayscale
|
| 245 |
gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
|
|
|
| 237 |
def get_depth_map(self, image):
|
| 238 |
"""Generate depth map using Zoe Depth"""
|
| 239 |
if self.zoe_depth is not None:
|
| 240 |
+
try:
|
| 241 |
+
# Ensure clean PIL Image to avoid numpy type issues in ZoeDepth
|
| 242 |
+
# Convert to RGB explicitly to ensure proper format
|
| 243 |
+
if image.mode != 'RGB':
|
| 244 |
+
image = image.convert('RGB')
|
| 245 |
+
|
| 246 |
+
# Get dimensions and ensure they're Python ints
|
| 247 |
+
width, height = image.size
|
| 248 |
+
width, height = int(width), int(height)
|
| 249 |
+
|
| 250 |
+
# Create a fresh image to avoid any numpy type contamination
|
| 251 |
+
# This fixes the nn.functional.interpolate numpy.int64 error
|
| 252 |
+
image_array = np.array(image)
|
| 253 |
+
clean_image = Image.fromarray(image_array.astype(np.uint8))
|
| 254 |
+
|
| 255 |
+
# Use Zoe detector
|
| 256 |
+
depth_image = self.zoe_depth(clean_image)
|
| 257 |
+
return depth_image
|
| 258 |
+
except Exception as e:
|
| 259 |
+
print(f"Warning: ZoeDetector failed ({e}), falling back to grayscale depth")
|
| 260 |
+
# Fallback if ZoeDetector fails
|
| 261 |
+
gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
| 262 |
+
depth_colored = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
|
| 263 |
+
return Image.fromarray(depth_colored)
|
| 264 |
else:
|
| 265 |
# Fallback to simple grayscale
|
| 266 |
gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|