Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -100,6 +100,31 @@ class RetroArtConverter:
|
|
| 100 |
try:
|
| 101 |
self.zoe_depth = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
| 102 |
self.zoe_depth.to(self.device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
print("✓ Zoe Depth loaded successfully")
|
| 104 |
self.models_loaded['zoe_depth'] = True
|
| 105 |
except Exception as e:
|
|
@@ -237,7 +262,6 @@ 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 |
-
# --- FIX: Pass correct dimensions ---
|
| 241 |
# Get the size from the PIL image
|
| 242 |
w, h = image.size
|
| 243 |
|
|
@@ -252,7 +276,6 @@ class RetroArtConverter:
|
|
| 252 |
detect_resolution=512, # Use a standard int value
|
| 253 |
image_resolution=(w_int, h_int) # Pass the tuple here
|
| 254 |
)
|
| 255 |
-
# --- END FIX ---
|
| 256 |
return depth_image
|
| 257 |
else:
|
| 258 |
# Fallback to simple grayscale
|
|
@@ -318,7 +341,7 @@ class RetroArtConverter:
|
|
| 318 |
original_width, original_height = input_image.size
|
| 319 |
target_width, target_height = self.calculate_optimal_size(original_width, original_height)
|
| 320 |
|
| 321 |
-
#
|
| 322 |
target_width = int(target_width)
|
| 323 |
target_height = int(target_height)
|
| 324 |
|
|
@@ -326,14 +349,12 @@ class RetroArtConverter:
|
|
| 326 |
print(f"Prompt: {prompt}")
|
| 327 |
print(f"Img2Img Strength: {strength}")
|
| 328 |
|
| 329 |
-
# --- FIX: CORRECT ORDER ---
|
| 330 |
# 1. Create resized_image FIRST...
|
| 331 |
resized_image = input_image.resize((target_width, target_height), Image.LANCZOS)
|
| 332 |
|
| 333 |
# 2. ...THEN pass it to get_depth_map.
|
| 334 |
print("Generating Zoe depth map...")
|
| 335 |
depth_image = self.get_depth_map(resized_image)
|
| 336 |
-
# --- END FIX ---
|
| 337 |
|
| 338 |
if depth_image.size != (target_width, target_height):
|
| 339 |
print(f"Warning: Depth map size {depth_image.size} does not match target {target_width}x{target_height}. Resizing...")
|
|
|
|
| 100 |
try:
|
| 101 |
self.zoe_depth = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
| 102 |
self.zoe_depth.to(self.device)
|
| 103 |
+
|
| 104 |
+
# --- MONKEY-PATCH FIX for numpy.int64 TypeError ---
|
| 105 |
+
# The ZoeDetector's internal Midas model (self.zoe_depth.model.core.prep.resizer)
|
| 106 |
+
# has its 'height' and 'width' attributes as numpy.int64,
|
| 107 |
+
# which torch.nn.functional.interpolate dislikes.
|
| 108 |
+
# We explicitly cast them to standard Python int.
|
| 109 |
+
if hasattr(self.zoe_depth, 'model') and \
|
| 110 |
+
hasattr(self.zoe_depth.model, 'core') and \
|
| 111 |
+
hasattr(self.zoe_depth.model.core, 'prep') and \
|
| 112 |
+
hasattr(self.zoe_depth.model.core.prep, 'resizer'):
|
| 113 |
+
|
| 114 |
+
print("Applying monkey-patch to ZoeDepth model resizer...")
|
| 115 |
+
resizer = self.zoe_depth.model.core.prep.resizer
|
| 116 |
+
|
| 117 |
+
if hasattr(resizer, 'height') and not isinstance(resizer.height, int):
|
| 118 |
+
resizer.height = int(resizer.height)
|
| 119 |
+
print(f" Patched resizer.height to type: {type(resizer.height)}")
|
| 120 |
+
|
| 121 |
+
if hasattr(resizer, 'width') and not isinstance(resizer.width, int):
|
| 122 |
+
resizer.width = int(resizer.width)
|
| 123 |
+
print(f" Patched resizer.width to type: {type(resizer.width)}")
|
| 124 |
+
|
| 125 |
+
print("Monkey-patch applied.")
|
| 126 |
+
# --- END MONKEY-PATCH ---
|
| 127 |
+
|
| 128 |
print("✓ Zoe Depth loaded successfully")
|
| 129 |
self.models_loaded['zoe_depth'] = True
|
| 130 |
except Exception as e:
|
|
|
|
| 262 |
def get_depth_map(self, image):
|
| 263 |
"""Generate depth map using Zoe Depth"""
|
| 264 |
if self.zoe_depth is not None:
|
|
|
|
| 265 |
# Get the size from the PIL image
|
| 266 |
w, h = image.size
|
| 267 |
|
|
|
|
| 276 |
detect_resolution=512, # Use a standard int value
|
| 277 |
image_resolution=(w_int, h_int) # Pass the tuple here
|
| 278 |
)
|
|
|
|
| 279 |
return depth_image
|
| 280 |
else:
|
| 281 |
# Fallback to simple grayscale
|
|
|
|
| 341 |
original_width, original_height = input_image.size
|
| 342 |
target_width, target_height = self.calculate_optimal_size(original_width, original_height)
|
| 343 |
|
| 344 |
+
# Cast to int() to prevent numpy.int64 errors
|
| 345 |
target_width = int(target_width)
|
| 346 |
target_height = int(target_height)
|
| 347 |
|
|
|
|
| 349 |
print(f"Prompt: {prompt}")
|
| 350 |
print(f"Img2Img Strength: {strength}")
|
| 351 |
|
|
|
|
| 352 |
# 1. Create resized_image FIRST...
|
| 353 |
resized_image = input_image.resize((target_width, target_height), Image.LANCZOS)
|
| 354 |
|
| 355 |
# 2. ...THEN pass it to get_depth_map.
|
| 356 |
print("Generating Zoe depth map...")
|
| 357 |
depth_image = self.get_depth_map(resized_image)
|
|
|
|
| 358 |
|
| 359 |
if depth_image.size != (target_width, target_height):
|
| 360 |
print(f"Warning: Depth map size {depth_image.size} does not match target {target_width}x{target_height}. Resizing...")
|