primerz commited on
Commit
795fbb2
·
verified ·
1 Parent(s): 3c10809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -50
app.py CHANGED
@@ -100,31 +100,6 @@ class RetroArtConverter:
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,20 +237,8 @@ class RetroArtConverter:
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
-
268
- # Ensure they are standard Python ints, not numpy.int64
269
- w_int, h_int = int(w), int(h)
270
-
271
- # detect_resolution expects an INT (for shortest side)
272
- # image_resolution expects a TUPLE (width, height)
273
- print(f" Generating Zoe depth map at {w_int}x{h_int} resolution...")
274
- depth_image = self.zoe_depth(
275
- image,
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,24 +304,18 @@ class RetroArtConverter:
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
-
348
  print(f"Resizing from {original_width}x{original_height} to {target_width}x{target_height}")
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...")
361
- depth_image = depth_image.resize((target_width, target_height), Image.LANCZOS)
362
 
363
  # Handle face detection for InstantID
364
  using_multiple_controlnets = self.using_multiple_controlnets
 
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
  def get_depth_map(self, image):
238
  """Generate depth map using Zoe Depth"""
239
  if self.zoe_depth is not None:
240
+ # Use Zoe detector
241
+ depth_image = self.zoe_depth(image, detect_resolution=512, image_resolution=1024)
 
 
 
 
 
 
 
 
 
 
 
 
242
  return depth_image
243
  else:
244
  # Fallback to simple grayscale
 
304
  original_width, original_height = input_image.size
305
  target_width, target_height = self.calculate_optimal_size(original_width, original_height)
306
 
 
 
 
 
307
  print(f"Resizing from {original_width}x{original_height} to {target_width}x{target_height}")
308
  print(f"Prompt: {prompt}")
309
  print(f"Img2Img Strength: {strength}")
 
 
 
310
 
311
+ # Resize with high quality - ensure dimensions are Python ints
312
+ resized_image = input_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
313
+
314
+ # Generate depth map using Zoe
315
  print("Generating Zoe depth map...")
316
  depth_image = self.get_depth_map(resized_image)
 
317
  if depth_image.size != (target_width, target_height):
318
+ depth_image = depth_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
 
319
 
320
  # Handle face detection for InstantID
321
  using_multiple_controlnets = self.using_multiple_controlnets