Spaces:
Running
on
Zero
Running
on
Zero
Update generator.py
Browse files- generator.py +20 -8
generator.py
CHANGED
|
@@ -71,7 +71,6 @@ class Generator:
|
|
| 71 |
if face_info is not None:
|
| 72 |
print("Face detected: Applying InstantID with keypoints.")
|
| 73 |
|
| 74 |
-
# --- FIX APPLIED HERE ---
|
| 75 |
# We use face_info['embedding'] (raw) instead of normed_embedding.
|
| 76 |
# Raw embedding has higher magnitude (~20-30) required for the adapter.
|
| 77 |
face_emb = torch.tensor(
|
|
@@ -79,28 +78,41 @@ class Generator:
|
|
| 79 |
dtype=Config.DTYPE,
|
| 80 |
device=Config.DEVICE
|
| 81 |
).unsqueeze(0)
|
| 82 |
-
# --- END FIX ---
|
| 83 |
|
| 84 |
# Create keypoint image
|
| 85 |
face_kps = draw_kps(processed_image, face_info['kps'])
|
| 86 |
-
|
|
|
|
| 87 |
controlnet_conditioning_scale = [face_strength, depth_strength, lineart_strength]
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
else:
|
| 90 |
print("No face detected: Disabling InstantID.")
|
| 91 |
# Create dummy embedding
|
| 92 |
face_emb = torch.zeros((1, 512), dtype=Config.DTYPE, device=Config.DEVICE)
|
| 93 |
# Create dummy keypoint image (black)
|
| 94 |
face_kps = Image.new('RGB', (target_width, target_height), (0, 0, 0))
|
| 95 |
-
face_kps_guidance_end = 0.001
|
| 96 |
-
face_strength_end = 0.001
|
| 97 |
|
| 98 |
# Set strengths
|
| 99 |
controlnet_conditioning_scale = [0.0, depth_strength, lineart_strength]
|
| 100 |
self.mh.pipeline.set_ip_adapter_scale(0.0)
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
# --- Seed/Generator Logic ---
|
| 106 |
if seed == -1 or seed is None:
|
|
|
|
| 71 |
if face_info is not None:
|
| 72 |
print("Face detected: Applying InstantID with keypoints.")
|
| 73 |
|
|
|
|
| 74 |
# We use face_info['embedding'] (raw) instead of normed_embedding.
|
| 75 |
# Raw embedding has higher magnitude (~20-30) required for the adapter.
|
| 76 |
face_emb = torch.tensor(
|
|
|
|
| 78 |
dtype=Config.DTYPE,
|
| 79 |
device=Config.DEVICE
|
| 80 |
).unsqueeze(0)
|
|
|
|
| 81 |
|
| 82 |
# Create keypoint image
|
| 83 |
face_kps = draw_kps(processed_image, face_info['kps'])
|
| 84 |
+
|
| 85 |
+
# Set strengths
|
| 86 |
controlnet_conditioning_scale = [face_strength, depth_strength, lineart_strength]
|
| 87 |
+
|
| 88 |
+
# --- UPDATED: Reduced IP Adapter Scale ---
|
| 89 |
+
# Lowered from 0.8 to 0.7 to allow LoRA style (pixel art) to
|
| 90 |
+
# override realistic skin textures while keeping identity.
|
| 91 |
+
self.mh.pipeline.set_ip_adapter_scale(0.7)
|
| 92 |
else:
|
| 93 |
print("No face detected: Disabling InstantID.")
|
| 94 |
# Create dummy embedding
|
| 95 |
face_emb = torch.zeros((1, 512), dtype=Config.DTYPE, device=Config.DEVICE)
|
| 96 |
# Create dummy keypoint image (black)
|
| 97 |
face_kps = Image.new('RGB', (target_width, target_height), (0, 0, 0))
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Set strengths
|
| 100 |
controlnet_conditioning_scale = [0.0, depth_strength, lineart_strength]
|
| 101 |
self.mh.pipeline.set_ip_adapter_scale(0.0)
|
| 102 |
|
| 103 |
+
# --- UPDATED: Control Guidance End Strategy ---
|
| 104 |
+
# We cap the Face ControlNet duration.
|
| 105 |
+
# Even if strength is 1.0, we stop it at 0.6 (60%) of the steps.
|
| 106 |
+
# This leaves the final 40% of steps pure for the Pixel Art LoRA
|
| 107 |
+
# to "pixelize" the face without the ControlNet trying to fix it back to a photo.
|
| 108 |
+
|
| 109 |
+
face_end_step = min(0.6, face_strength)
|
| 110 |
+
|
| 111 |
+
control_guidance_end = [
|
| 112 |
+
face_end_step, # InstantID: Stop early for style
|
| 113 |
+
depth_strength, # Depth: Keep structure longer
|
| 114 |
+
lineart_strength # Lineart: Keep outlines longer
|
| 115 |
+
]
|
| 116 |
|
| 117 |
# --- Seed/Generator Logic ---
|
| 118 |
if seed == -1 or seed is None:
|