Spaces:
Runtime error
Runtime error
Update generator.py
Browse files- generator.py +5 -9
generator.py
CHANGED
|
@@ -810,7 +810,7 @@ class RetroArtConverter:
|
|
| 810 |
# 1. InstantID (Identity)
|
| 811 |
if self.instantid_active:
|
| 812 |
if has_detected_faces and face_kps_image is not None:
|
| 813 |
-
#
|
| 814 |
face_kps_image = ensure_correct_size(face_kps_image, target_width, target_height, "InstantID")
|
| 815 |
control_images.append(face_kps_image)
|
| 816 |
conditioning_scales.append(identity_control_scale)
|
|
@@ -830,16 +830,12 @@ class RetroArtConverter:
|
|
| 830 |
|
| 831 |
print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
|
| 832 |
|
| 833 |
-
# --- START FIX
|
| 834 |
if 'prompt_embeds' in pipe_kwargs:
|
| 835 |
original_embeds = pipe_kwargs['prompt_embeds']
|
| 836 |
|
| 837 |
-
# Handle CFG by creating a [2, 16, 2048] tensor
|
| 838 |
-
# [0] is zeros for negative, [1] is face embeds for positive
|
| 839 |
-
face_proj_embeds_cfg = torch.cat([torch.zeros_like(face_proj_embeds), face_proj_embeds], dim=0)
|
| 840 |
-
|
| 841 |
# Concatenate face embeddings to POSITIVE prompt
|
| 842 |
-
combined_embeds = torch.cat([original_embeds,
|
| 843 |
pipe_kwargs['prompt_embeds'] = combined_embeds
|
| 844 |
|
| 845 |
# CRITICAL: Pad negative_prompt_embeds by the same amount
|
|
@@ -862,13 +858,13 @@ class RetroArtConverter:
|
|
| 862 |
print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
|
| 863 |
else:
|
| 864 |
print(f" [WARNING] Can't concatenate - no prompt_embeds (use Compel)")
|
| 865 |
-
# --- END FIX
|
| 866 |
|
| 867 |
elif has_detected_faces:
|
| 868 |
print(" Face detected but IP-Adapter/embeddings unavailable, using keypoints only")
|
| 869 |
|
| 870 |
else:
|
| 871 |
-
#
|
| 872 |
print("[INSTANTID] Using blank map (scale=0, no effect on generation)")
|
| 873 |
control_images.append(Image.new("RGB", (target_width, target_height), (0,0,0)))
|
| 874 |
conditioning_scales.append(0.0) # Set scale to 0
|
|
|
|
| 810 |
# 1. InstantID (Identity)
|
| 811 |
if self.instantid_active:
|
| 812 |
if has_detected_faces and face_kps_image is not None:
|
| 813 |
+
# Ensure face keypoints image has correct size
|
| 814 |
face_kps_image = ensure_correct_size(face_kps_image, target_width, target_height, "InstantID")
|
| 815 |
control_images.append(face_kps_image)
|
| 816 |
conditioning_scales.append(identity_control_scale)
|
|
|
|
| 830 |
|
| 831 |
print(f" - Face embedding: {face_proj_embeds.shape}, Scale: {boosted_scale:.2f}")
|
| 832 |
|
| 833 |
+
# --- START FIX: Your padding solution ---
|
| 834 |
if 'prompt_embeds' in pipe_kwargs:
|
| 835 |
original_embeds = pipe_kwargs['prompt_embeds']
|
| 836 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
# Concatenate face embeddings to POSITIVE prompt
|
| 838 |
+
combined_embeds = torch.cat([original_embeds, face_proj_embeds], dim=1)
|
| 839 |
pipe_kwargs['prompt_embeds'] = combined_embeds
|
| 840 |
|
| 841 |
# CRITICAL: Pad negative_prompt_embeds by the same amount
|
|
|
|
| 858 |
print(f" [OK] Face embeddings concatenated successfully! Prompt: {combined_embeds.shape}")
|
| 859 |
else:
|
| 860 |
print(f" [WARNING] Can't concatenate - no prompt_embeds (use Compel)")
|
| 861 |
+
# --- END FIX ---
|
| 862 |
|
| 863 |
elif has_detected_faces:
|
| 864 |
print(" Face detected but IP-Adapter/embeddings unavailable, using keypoints only")
|
| 865 |
|
| 866 |
else:
|
| 867 |
+
# No face detected - blank map needed to maintain ControlNet list order
|
| 868 |
print("[INSTANTID] Using blank map (scale=0, no effect on generation)")
|
| 869 |
control_images.append(Image.new("RGB", (target_width, target_height), (0,0,0)))
|
| 870 |
conditioning_scales.append(0.0) # Set scale to 0
|