primerz commited on
Commit
0775e46
·
verified ·
1 Parent(s): f30dc7a

Update generator.py

Browse files
Files changed (1) hide show
  1. generator.py +21 -3
generator.py CHANGED
@@ -153,6 +153,7 @@ class RetroArtConverter:
153
  image = image.convert('RGB')
154
 
155
  orig_width, orig_height = image.size
 
156
  orig_width = int(orig_width)
157
  orig_height = int(orig_height)
158
 
@@ -163,17 +164,25 @@ class RetroArtConverter:
163
  target_width = int(max(64, target_width))
164
  target_height = int(max(64, target_height))
165
 
 
 
 
 
 
 
 
166
  if target_width != orig_width or target_height != orig_height:
167
- image = image.resize((int(target_width), int(target_height)), Image.LANCZOS)
168
  print(f"[DEPTH] Resized for ZoeDetector: {orig_width}x{orig_height} -> {target_width}x{target_height}")
169
 
170
  # FIXED: Add torch.no_grad() wrapper
171
  with torch.no_grad():
172
- depth_image = self.zoe_depth(image)
173
 
174
  depth_width, depth_height = depth_image.size
175
  if depth_width != orig_width or depth_height != orig_height:
 
176
  depth_image = depth_image.resize((int(orig_width), int(orig_height)), Image.LANCZOS)
 
177
 
178
  print(f"[DEPTH] Zoe depth map generated: {orig_width}x{orig_height}")
179
  return depth_image
@@ -192,6 +201,10 @@ class RetroArtConverter:
192
  def add_trigger_word(self, prompt):
193
  """Add trigger word to prompt if not present"""
194
  if TRIGGER_WORD.lower() not in prompt.lower():
 
 
 
 
195
  return f"{TRIGGER_WORD}, {prompt}"
196
  return prompt
197
 
@@ -437,6 +450,11 @@ class RetroArtConverter:
437
  prompt = sanitize_text(prompt)
438
  negative_prompt = sanitize_text(negative_prompt)
439
 
 
 
 
 
 
440
  # Apply parameter validation
441
  if consistency_mode:
442
  print("\n[CONSISTENCY] Validating and adjusting parameters...")
@@ -446,7 +464,7 @@ class RetroArtConverter:
446
  identity_control_scale, depth_control_scale, consistency_mode
447
  )
448
 
449
- # Add trigger word
450
  prompt = self.add_trigger_word(prompt)
451
 
452
  # Calculate optimal size with flexible aspect ratio support
 
153
  image = image.convert('RGB')
154
 
155
  orig_width, orig_height = image.size
156
+ # **FIX 1 START: Ensure all size variables are standard Python int**
157
  orig_width = int(orig_width)
158
  orig_height = int(orig_height)
159
 
 
164
  target_width = int(max(64, target_width))
165
  target_height = int(max(64, target_height))
166
 
167
+ # Create an explicit tuple of standard ints
168
+ size_for_depth = (int(target_width), int(target_height))
169
+
170
+ # Always resize using the explicit int tuple to avoid numpy.int64 issues
171
+ # This replaces the conditional resize
172
+ image_for_depth = image.resize(size_for_depth, Image.LANCZOS)
173
+
174
  if target_width != orig_width or target_height != orig_height:
 
175
  print(f"[DEPTH] Resized for ZoeDetector: {orig_width}x{orig_height} -> {target_width}x{target_height}")
176
 
177
  # FIXED: Add torch.no_grad() wrapper
178
  with torch.no_grad():
179
+ depth_image = self.zoe_depth(image_for_depth) # Use the correctly-typed resized image
180
 
181
  depth_width, depth_height = depth_image.size
182
  if depth_width != orig_width or depth_height != orig_height:
183
+ # Resize back to the original size that get_depth_map received
184
  depth_image = depth_image.resize((int(orig_width), int(orig_height)), Image.LANCZOS)
185
+ # **FIX 1 END**
186
 
187
  print(f"[DEPTH] Zoe depth map generated: {orig_width}x{orig_height}")
188
  return depth_image
 
201
  def add_trigger_word(self, prompt):
202
  """Add trigger word to prompt if not present"""
203
  if TRIGGER_WORD.lower() not in prompt.lower():
204
+ # **FIX 3 START: Handle empty or blank prompt**
205
+ if not prompt or not prompt.strip():
206
+ return TRIGGER_WORD
207
+ # **FIX 3 END**
208
  return f"{TRIGGER_WORD}, {prompt}"
209
  return prompt
210
 
 
450
  prompt = sanitize_text(prompt)
451
  negative_prompt = sanitize_text(negative_prompt)
452
 
453
+ # **FIX 3 START: Ensure blank negative prompts are empty strings for Compel**
454
+ if not negative_prompt or not negative_prompt.strip():
455
+ negative_prompt = ""
456
+ # **FIX 3 END**
457
+
458
  # Apply parameter validation
459
  if consistency_mode:
460
  print("\n[CONSISTENCY] Validating and adjusting parameters...")
 
464
  identity_control_scale, depth_control_scale, consistency_mode
465
  )
466
 
467
+ # Add trigger word (handles blank prompt fix)
468
  prompt = self.add_trigger_word(prompt)
469
 
470
  # Calculate optimal size with flexible aspect ratio support