Spaces:
Runtime error
Runtime error
Update generator.py
Browse files- generator.py +18 -47
generator.py
CHANGED
|
@@ -153,11 +153,17 @@ class RetroArtConverter:
|
|
| 153 |
if image.mode != 'RGB':
|
| 154 |
image = image.convert('RGB')
|
| 155 |
|
| 156 |
-
#
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
depth_image = self.zoe_depth(image)
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
return depth_image
|
| 162 |
|
| 163 |
except Exception as e:
|
|
@@ -595,57 +601,22 @@ class RetroArtConverter:
|
|
| 595 |
try:
|
| 596 |
print("Encoding prompts with Compel...")
|
| 597 |
|
| 598 |
-
# Encode prompts
|
| 599 |
conditioning = self.compel(prompt)
|
| 600 |
negative_conditioning = self.compel(negative_prompt)
|
| 601 |
|
| 602 |
-
# Extract embeddings
|
| 603 |
-
prompt_embeds = conditioning[0]
|
| 604 |
-
pooled_prompt_embeds = conditioning[1]
|
| 605 |
-
negative_prompt_embeds = negative_conditioning[0]
|
| 606 |
-
negative_pooled_prompt_embeds = negative_conditioning[1]
|
| 607 |
-
|
| 608 |
-
# Ensure consistent shapes (SDXL uses 77 tokens max)
|
| 609 |
-
max_length = max(prompt_embeds.shape[1], negative_prompt_embeds.shape[1])
|
| 610 |
-
|
| 611 |
-
# Pad if needed
|
| 612 |
-
if prompt_embeds.shape[1] < max_length:
|
| 613 |
-
padding = torch.zeros(
|
| 614 |
-
prompt_embeds.shape[0],
|
| 615 |
-
max_length - prompt_embeds.shape[1],
|
| 616 |
-
prompt_embeds.shape[2],
|
| 617 |
-
dtype=prompt_embeds.dtype,
|
| 618 |
-
device=prompt_embeds.device
|
| 619 |
-
)
|
| 620 |
-
prompt_embeds = torch.cat([prompt_embeds, padding], dim=1)
|
| 621 |
-
|
| 622 |
-
if negative_prompt_embeds.shape[1] < max_length:
|
| 623 |
-
padding = torch.zeros(
|
| 624 |
-
negative_prompt_embeds.shape[0],
|
| 625 |
-
max_length - negative_prompt_embeds.shape[1],
|
| 626 |
-
negative_prompt_embeds.shape[2],
|
| 627 |
-
dtype=negative_prompt_embeds.dtype,
|
| 628 |
-
device=negative_prompt_embeds.device
|
| 629 |
-
)
|
| 630 |
-
negative_prompt_embeds = torch.cat([negative_prompt_embeds, padding], dim=1)
|
| 631 |
-
|
| 632 |
-
# Truncate if needed
|
| 633 |
-
if prompt_embeds.shape[1] > 77:
|
| 634 |
-
prompt_embeds = prompt_embeds[:, :77, :]
|
| 635 |
-
if negative_prompt_embeds.shape[1] > 77:
|
| 636 |
-
negative_prompt_embeds = negative_prompt_embeds[:, :77, :]
|
| 637 |
-
|
| 638 |
-
pipe_kwargs["prompt_embeds"] = prompt_embeds
|
| 639 |
-
pipe_kwargs["pooled_prompt_embeds"] = pooled_prompt_embeds
|
| 640 |
-
pipe_kwargs["negative_prompt_embeds"] = negative_prompt_embeds
|
| 641 |
-
pipe_kwargs["negative_pooled_prompt_embeds"] = negative_pooled_prompt_embeds
|
| 642 |
|
| 643 |
compel_success = True
|
| 644 |
-
print(
|
| 645 |
|
| 646 |
except Exception as e:
|
| 647 |
-
print(f"[COMPEL]
|
| 648 |
-
print("[COMPEL]
|
| 649 |
compel_success = False
|
| 650 |
|
| 651 |
# Use standard prompts if Compel failed or not available
|
|
|
|
| 153 |
if image.mode != 'RGB':
|
| 154 |
image = image.convert('RGB')
|
| 155 |
|
| 156 |
+
# Get original dimensions
|
| 157 |
+
orig_width, orig_height = image.size
|
| 158 |
+
|
| 159 |
+
# ZoeDetector handles sizing internally - just pass the image
|
| 160 |
depth_image = self.zoe_depth(image)
|
| 161 |
|
| 162 |
+
# Ensure output matches original size
|
| 163 |
+
if depth_image.size != (orig_width, orig_height):
|
| 164 |
+
depth_image = depth_image.resize((orig_width, orig_height), Image.LANCZOS)
|
| 165 |
+
|
| 166 |
+
print(f"[DEPTH] Zoe depth map generated: {orig_width}x{orig_height}")
|
| 167 |
return depth_image
|
| 168 |
|
| 169 |
except Exception as e:
|
|
|
|
| 601 |
try:
|
| 602 |
print("Encoding prompts with Compel...")
|
| 603 |
|
| 604 |
+
# Encode prompts with Compel
|
| 605 |
conditioning = self.compel(prompt)
|
| 606 |
negative_conditioning = self.compel(negative_prompt)
|
| 607 |
|
| 608 |
+
# Extract embeddings
|
| 609 |
+
pipe_kwargs["prompt_embeds"] = conditioning[0]
|
| 610 |
+
pipe_kwargs["pooled_prompt_embeds"] = conditioning[1]
|
| 611 |
+
pipe_kwargs["negative_prompt_embeds"] = negative_conditioning[0]
|
| 612 |
+
pipe_kwargs["negative_pooled_prompt_embeds"] = negative_conditioning[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
|
| 614 |
compel_success = True
|
| 615 |
+
print("[OK] Using Compel-encoded prompts")
|
| 616 |
|
| 617 |
except Exception as e:
|
| 618 |
+
print(f"[COMPEL] Encoding failed: {e}")
|
| 619 |
+
print(f"[COMPEL] Using standard prompt encoding instead")
|
| 620 |
compel_success = False
|
| 621 |
|
| 622 |
# Use standard prompts if Compel failed or not available
|