Spaces:
Runtime error
Runtime error
Update generator.py
Browse files- generator.py +20 -17
generator.py
CHANGED
|
@@ -20,7 +20,10 @@ from utils import (
|
|
| 20 |
)
|
| 21 |
from models import (
|
| 22 |
load_face_analysis, load_depth_detector, load_controlnets, load_image_encoder,
|
| 23 |
-
load_sdxl_pipeline, load_loras, setup_ip_adapter,
|
|
|
|
|
|
|
|
|
|
| 24 |
setup_scheduler, optimize_pipeline, load_caption_model, set_clip_skip,
|
| 25 |
load_openpose_detector, load_mediapipe_face_detector
|
| 26 |
)
|
|
@@ -127,8 +130,9 @@ class RetroArtConverter:
|
|
| 127 |
self.models_loaded['ip_adapter'] = False
|
| 128 |
self.image_proj_model = None
|
| 129 |
|
| 130 |
-
# Setup
|
| 131 |
-
self.
|
|
|
|
| 132 |
|
| 133 |
# Setup LCM scheduler
|
| 134 |
setup_scheduler(self.pipe)
|
|
@@ -773,29 +777,28 @@ class RetroArtConverter:
|
|
| 773 |
|
| 774 |
pipe_kwargs["generator"] = generator
|
| 775 |
|
| 776 |
-
# --- START FIX: Use
|
| 777 |
-
|
| 778 |
-
if self.use_compel and self.compel is not None:
|
| 779 |
try:
|
| 780 |
-
print("Encoding prompts with
|
| 781 |
|
| 782 |
-
# Call
|
| 783 |
-
|
| 784 |
-
conditioning = self.compel(prompt, negative_prompt=negative_prompt)
|
| 785 |
|
| 786 |
-
# Unpack the results
|
| 787 |
pipe_kwargs["prompt_embeds"] = conditioning.embeds
|
| 788 |
pipe_kwargs["pooled_prompt_embeds"] = conditioning.pooled_embeds
|
| 789 |
pipe_kwargs["negative_prompt_embeds"] = conditioning.negative_embeds
|
| 790 |
pipe_kwargs["negative_pooled_prompt_embeds"] = conditioning.negative_pooled_embeds
|
| 791 |
|
| 792 |
-
print(f"[OK]
|
| 793 |
except Exception as e:
|
| 794 |
-
print(f"
|
| 795 |
traceback.print_exc()
|
| 796 |
pipe_kwargs["prompt"] = prompt
|
| 797 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 798 |
else:
|
|
|
|
| 799 |
pipe_kwargs["prompt"] = prompt
|
| 800 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 801 |
# --- END FIX ---
|
|
@@ -842,8 +845,8 @@ class RetroArtConverter:
|
|
| 842 |
|
| 843 |
print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
|
| 844 |
|
| 845 |
-
# --- START FIX
|
| 846 |
-
# This fixes the "109 vs
|
| 847 |
if 'prompt_embeds' in pipe_kwargs:
|
| 848 |
original_embeds = pipe_kwargs['prompt_embeds']
|
| 849 |
|
|
@@ -870,7 +873,7 @@ class RetroArtConverter:
|
|
| 870 |
|
| 871 |
print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
|
| 872 |
else:
|
| 873 |
-
print(f" [WARNING] Can't concatenate - no prompt_embeds (use
|
| 874 |
# --- END FIX 2 ---
|
| 875 |
|
| 876 |
elif has_detected_faces:
|
|
@@ -947,4 +950,4 @@ class RetroArtConverter:
|
|
| 947 |
return generated_image
|
| 948 |
|
| 949 |
|
| 950 |
-
print("[OK] Generator class ready")
|
|
|
|
| 20 |
)
|
| 21 |
from models import (
|
| 22 |
load_face_analysis, load_depth_detector, load_controlnets, load_image_encoder,
|
| 23 |
+
load_sdxl_pipeline, load_loras, setup_ip_adapter,
|
| 24 |
+
# --- START FIX: Import setup_cappella ---
|
| 25 |
+
setup_cappella,
|
| 26 |
+
# --- END FIX ---
|
| 27 |
setup_scheduler, optimize_pipeline, load_caption_model, set_clip_skip,
|
| 28 |
load_openpose_detector, load_mediapipe_face_detector
|
| 29 |
)
|
|
|
|
| 130 |
self.models_loaded['ip_adapter'] = False
|
| 131 |
self.image_proj_model = None
|
| 132 |
|
| 133 |
+
# --- START FIX: Setup Cappella ---
|
| 134 |
+
self.cappella, self.use_cappella = setup_cappella(self.pipe)
|
| 135 |
+
# --- END FIX ---
|
| 136 |
|
| 137 |
# Setup LCM scheduler
|
| 138 |
setup_scheduler(self.pipe)
|
|
|
|
| 777 |
|
| 778 |
pipe_kwargs["generator"] = generator
|
| 779 |
|
| 780 |
+
# --- START FIX: Use our new Cappella module ---
|
| 781 |
+
if self.use_cappella and self.cappella is not None:
|
|
|
|
| 782 |
try:
|
| 783 |
+
print("Encoding prompts with Cappella...")
|
| 784 |
|
| 785 |
+
# Call Cappella once. It handles truncation and padding.
|
| 786 |
+
conditioning = self.cappella(prompt, negative_prompt)
|
|
|
|
| 787 |
|
| 788 |
+
# Unpack the results
|
| 789 |
pipe_kwargs["prompt_embeds"] = conditioning.embeds
|
| 790 |
pipe_kwargs["pooled_prompt_embeds"] = conditioning.pooled_embeds
|
| 791 |
pipe_kwargs["negative_prompt_embeds"] = conditioning.negative_embeds
|
| 792 |
pipe_kwargs["negative_pooled_prompt_embeds"] = conditioning.negative_pooled_embeds
|
| 793 |
|
| 794 |
+
print(f"[OK] Cappella encoded - Prompt: {pipe_kwargs['prompt_embeds'].shape}, Negative: {pipe_kwargs['negative_prompt_embeds'].shape}")
|
| 795 |
except Exception as e:
|
| 796 |
+
print(f"Cappella encoding failed, using standard prompts: {e}")
|
| 797 |
traceback.print_exc()
|
| 798 |
pipe_kwargs["prompt"] = prompt
|
| 799 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 800 |
else:
|
| 801 |
+
print("[WARNING] Cappella not found, using standard prompt encoding.")
|
| 802 |
pipe_kwargs["prompt"] = prompt
|
| 803 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 804 |
# --- END FIX ---
|
|
|
|
| 845 |
|
| 846 |
print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
|
| 847 |
|
| 848 |
+
# --- START FIX: Your padding solution ---
|
| 849 |
+
# This fixes the "109 vs 77" error
|
| 850 |
if 'prompt_embeds' in pipe_kwargs:
|
| 851 |
original_embeds = pipe_kwargs['prompt_embeds']
|
| 852 |
|
|
|
|
| 873 |
|
| 874 |
print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
|
| 875 |
else:
|
| 876 |
+
print(f" [WARNING] Can't concatenate - no prompt_embeds (use Cappella)")
|
| 877 |
# --- END FIX 2 ---
|
| 878 |
|
| 879 |
elif has_detected_faces:
|
|
|
|
| 950 |
return generated_image
|
| 951 |
|
| 952 |
|
| 953 |
+
print("[OK] Generator class ready")
|