Spaces:
Runtime error
Runtime error
Update generator.py
Browse files- generator.py +43 -23
generator.py
CHANGED
|
@@ -160,15 +160,17 @@ class RetroArtConverter:
|
|
| 160 |
orig_height = int(orig_height.item() if hasattr(orig_height, 'item') else orig_height)
|
| 161 |
|
| 162 |
# Resize to dimensions ZoeDetector expects (multiples of 32)
|
| 163 |
-
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
# Ensure at least 32x32
|
| 167 |
-
target_width = max(32, target_width)
|
| 168 |
-
target_height = max(32, target_height)
|
| 169 |
|
| 170 |
if target_width != orig_width or target_height != orig_height:
|
| 171 |
-
|
|
|
|
| 172 |
print(f"[DEPTH] Resized for ZoeDetector: {orig_width}x{orig_height} -> {target_width}x{target_height}")
|
| 173 |
|
| 174 |
# Use Zoe detector - now with safe dimensions
|
|
@@ -552,29 +554,47 @@ class RetroArtConverter:
|
|
| 552 |
# Set LORA scale
|
| 553 |
if hasattr(self.pipe, 'set_adapters') and self.models_loaded['lora']:
|
| 554 |
try:
|
| 555 |
-
#
|
|
|
|
| 556 |
if hasattr(self.pipe, 'get_list_adapters'):
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
| 565 |
else:
|
| 566 |
-
#
|
| 567 |
-
|
| 568 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
except Exception as e:
|
| 570 |
-
print(f"[WARNING]
|
| 571 |
-
# Try
|
| 572 |
try:
|
| 573 |
if hasattr(self.pipe, 'fuse_lora'):
|
| 574 |
self.pipe.fuse_lora(lora_scale=lora_scale)
|
| 575 |
-
print(f"[
|
| 576 |
-
except:
|
| 577 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
|
| 579 |
# Prepare generation kwargs
|
| 580 |
pipe_kwargs = {
|
|
@@ -787,4 +807,4 @@ class RetroArtConverter:
|
|
| 787 |
return generated_image
|
| 788 |
|
| 789 |
|
| 790 |
-
print("[OK] Generator class ready")
|
|
|
|
| 160 |
orig_height = int(orig_height.item() if hasattr(orig_height, 'item') else orig_height)
|
| 161 |
|
| 162 |
# Resize to dimensions ZoeDetector expects (multiples of 32)
|
| 163 |
+
# CRITICAL: Ensure Python int, not numpy types
|
| 164 |
+
target_width = int((orig_width // 32) * 32)
|
| 165 |
+
target_height = int((orig_height // 32) * 32)
|
| 166 |
|
| 167 |
# Ensure at least 32x32
|
| 168 |
+
target_width = int(max(32, target_width))
|
| 169 |
+
target_height = int(max(32, target_height))
|
| 170 |
|
| 171 |
if target_width != orig_width or target_height != orig_height:
|
| 172 |
+
# CRITICAL: Pass explicit Python ints to resize
|
| 173 |
+
image = image.resize((int(target_width), int(target_height)), Image.LANCZOS)
|
| 174 |
print(f"[DEPTH] Resized for ZoeDetector: {orig_width}x{orig_height} -> {target_width}x{target_height}")
|
| 175 |
|
| 176 |
# Use Zoe detector - now with safe dimensions
|
|
|
|
| 554 |
# Set LORA scale
|
| 555 |
if hasattr(self.pipe, 'set_adapters') and self.models_loaded['lora']:
|
| 556 |
try:
|
| 557 |
+
# Get list of actually available adapters
|
| 558 |
+
available_adapters = []
|
| 559 |
if hasattr(self.pipe, 'get_list_adapters'):
|
| 560 |
+
try:
|
| 561 |
+
available_adapters = self.pipe.get_list_adapters()
|
| 562 |
+
print(f"[LORA] Available adapters: {available_adapters}")
|
| 563 |
+
except:
|
| 564 |
+
pass
|
| 565 |
+
|
| 566 |
+
if available_adapters:
|
| 567 |
+
# Use first available adapter (could be 'retroart', 'default_0', etc.)
|
| 568 |
+
adapter_name = available_adapters[0]
|
| 569 |
+
self.pipe.set_adapters([adapter_name], adapter_weights=[lora_scale])
|
| 570 |
+
print(f"[LORA] Using adapter '{adapter_name}' with scale: {lora_scale}")
|
| 571 |
else:
|
| 572 |
+
# No get_list_adapters or empty list - try common names
|
| 573 |
+
for name in ["retroart", "default", "default_0"]:
|
| 574 |
+
try:
|
| 575 |
+
self.pipe.set_adapters([name], adapter_weights=[lora_scale])
|
| 576 |
+
print(f"[LORA] Using adapter '{name}' with scale: {lora_scale}")
|
| 577 |
+
break
|
| 578 |
+
except:
|
| 579 |
+
continue
|
| 580 |
+
else:
|
| 581 |
+
print(f"[WARNING] Could not set LORA adapter scale")
|
| 582 |
+
|
| 583 |
except Exception as e:
|
| 584 |
+
print(f"[WARNING] LORA set_adapters failed: {e}")
|
| 585 |
+
# Try alternative method - fuse_lora
|
| 586 |
try:
|
| 587 |
if hasattr(self.pipe, 'fuse_lora'):
|
| 588 |
self.pipe.fuse_lora(lora_scale=lora_scale)
|
| 589 |
+
print(f"[LORA] Fused with scale: {lora_scale}")
|
| 590 |
+
except Exception as e2:
|
| 591 |
+
print(f"[WARNING] LORA fuse also failed: {e2}")
|
| 592 |
+
# Last resort - set scale directly if possible
|
| 593 |
+
try:
|
| 594 |
+
self.pipe.set_lora_scale(lora_scale)
|
| 595 |
+
print(f"[LORA] Set scale directly: {lora_scale}")
|
| 596 |
+
except:
|
| 597 |
+
print(f"[INFO] LORA will use default scale")
|
| 598 |
|
| 599 |
# Prepare generation kwargs
|
| 600 |
pipe_kwargs = {
|
|
|
|
| 807 |
return generated_image
|
| 808 |
|
| 809 |
|
| 810 |
+
print("[OK] Generator class ready")
|