primerz commited on
Commit
945ea91
·
verified ·
1 Parent(s): 4c13507

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -237,7 +237,7 @@ 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 ---
241
  # Get the size from the PIL image
242
  w, h = image.size
243
 
@@ -245,7 +245,8 @@ class RetroArtConverter:
245
  w_int, h_int = int(w), int(h)
246
 
247
  # Pass the image's own size as tuples to prevent
248
- # controlnet_aux from resizing to a square.
 
249
  depth_image = self.zoe_depth(
250
  image,
251
  detect_resolution=(w_int, h_int),
@@ -258,7 +259,7 @@ class RetroArtConverter:
258
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
259
  depth_colored = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
260
  return Image.fromarray(depth_colored)
261
-
262
  def calculate_optimal_size(self, original_width, original_height):
263
  """Calculate optimal size from recommended resolutions"""
264
  aspect_ratio = original_width / original_height
@@ -317,13 +318,26 @@ class RetroArtConverter:
317
  original_width, original_height = input_image.size
318
  target_width, target_height = self.calculate_optimal_size(original_width, original_height)
319
 
 
 
 
 
320
  print(f"Resizing from {original_width}x{original_height} to {target_width}x{target_height}")
 
 
 
 
 
 
321
 
322
- # Generate depth map using Zoe
323
  print("Generating Zoe depth map...")
324
  depth_image = self.get_depth_map(resized_image)
 
 
325
  if depth_image.size != (target_width, target_height):
326
- depth_image = depth_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
 
327
 
328
  # Handle face detection for InstantID
329
  using_multiple_controlnets = self.using_multiple_controlnets
 
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
 
 
245
  w_int, h_int = int(w), int(h)
246
 
247
  # Pass the image's own size as tuples to prevent
248
+ # controlnet_aux from resizing to a square and to fix TypeError.
249
+ print(f" Generating Zoe depth map at {w_int}x{h_int} resolution...")
250
  depth_image = self.zoe_depth(
251
  image,
252
  detect_resolution=(w_int, h_int),
 
259
  gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
260
  depth_colored = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
261
  return Image.fromarray(depth_colored)
262
+
263
  def calculate_optimal_size(self, original_width, original_height):
264
  """Calculate optimal size from recommended resolutions"""
265
  aspect_ratio = original_width / original_height
 
318
  original_width, original_height = input_image.size
319
  target_width, target_height = self.calculate_optimal_size(original_width, original_height)
320
 
321
+ # --- FIX: Cast to int() to prevent numpy.int64 errors ---
322
+ target_width = int(target_width)
323
+ target_height = int(target_height)
324
+
325
  print(f"Resizing from {original_width}x{original_height} to {target_width}x{target_height}")
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...")
340
+ depth_image = depth_image.resize((target_width, target_height), Image.LANCZOS)
341
 
342
  # Handle face detection for InstantID
343
  using_multiple_controlnets = self.using_multiple_controlnets