Spaces:
Running
on
Zero
Running
on
Zero
Update generator.py
Browse files- generator.py +18 -11
generator.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
from config import Config
|
| 3 |
-
from utils import resize_image_to_1mp, get_caption, draw_kps
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
class Generator:
|
|
@@ -24,18 +24,18 @@ class Generator:
|
|
| 24 |
depth_map = depth_map_raw.resize((width, height), Image.LANCZOS)
|
| 25 |
lineart_map = lineart_map_raw.resize((width, height), Image.LANCZOS)
|
| 26 |
|
| 27 |
-
return depth_map, lineart_map
|
| 28 |
|
| 29 |
def predict(
|
| 30 |
self,
|
| 31 |
input_image,
|
| 32 |
user_prompt="",
|
| 33 |
negative_prompt="",
|
| 34 |
-
guidance_scale=1.
|
| 35 |
-
num_inference_steps=
|
| 36 |
-
img2img_strength=0.
|
| 37 |
-
depth_strength=0.
|
| 38 |
-
lineart_strength=0.
|
| 39 |
seed=-1
|
| 40 |
):
|
| 41 |
# 1. Pre-process Inputs
|
|
@@ -68,8 +68,15 @@ class Generator:
|
|
| 68 |
# ControlNet order: [InstantID_KPS, Zoe_Depth, LineArt]
|
| 69 |
if face_info is not None:
|
| 70 |
print("Face detected: Applying InstantID with keypoints.")
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# Create keypoint image
|
| 74 |
face_kps = draw_kps(processed_image, face_info['kps'])
|
| 75 |
|
|
@@ -88,7 +95,7 @@ class Generator:
|
|
| 88 |
self.mh.pipeline.set_ip_adapter_scale(0.0)
|
| 89 |
|
| 90 |
# We keep the guidance_end for pose low
|
| 91 |
-
control_guidance_end = [0.
|
| 92 |
|
| 93 |
# --- Seed/Generator Logic ---
|
| 94 |
if seed == -1 or seed is None:
|
|
@@ -103,7 +110,7 @@ class Generator:
|
|
| 103 |
prompt=final_prompt,
|
| 104 |
negative_prompt=negative_prompt,
|
| 105 |
image=processed_image, # Base img2img image
|
| 106 |
-
control_image=[face_kps, depth_map, lineart_map],
|
| 107 |
image_embeds=face_emb, # Face identity embedding
|
| 108 |
generator=generator,
|
| 109 |
|
|
|
|
| 1 |
import torch
|
| 2 |
from config import Config
|
| 3 |
+
from utils import resize_image_to_1mp, get_caption, draw_kps
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
class Generator:
|
|
|
|
| 24 |
depth_map = depth_map_raw.resize((width, height), Image.LANCZOS)
|
| 25 |
lineart_map = lineart_map_raw.resize((width, height), Image.LANCZOS)
|
| 26 |
|
| 27 |
+
return depth_map, lineart_map
|
| 28 |
|
| 29 |
def predict(
|
| 30 |
self,
|
| 31 |
input_image,
|
| 32 |
user_prompt="",
|
| 33 |
negative_prompt="",
|
| 34 |
+
guidance_scale=1.5,
|
| 35 |
+
num_inference_steps=6,
|
| 36 |
+
img2img_strength=0.3,
|
| 37 |
+
depth_strength=0.3,
|
| 38 |
+
lineart_strength=0.3,
|
| 39 |
seed=-1
|
| 40 |
):
|
| 41 |
# 1. Pre-process Inputs
|
|
|
|
| 68 |
# ControlNet order: [InstantID_KPS, Zoe_Depth, LineArt]
|
| 69 |
if face_info is not None:
|
| 70 |
print("Face detected: Applying InstantID with keypoints.")
|
| 71 |
+
|
| 72 |
+
# --- MODIFIED: Explicitly cast tensor to Config.DTYPE ---
|
| 73 |
+
face_emb = torch.tensor(
|
| 74 |
+
face_info.normed_embedding,
|
| 75 |
+
dtype=Config.DTYPE, # <-- This is the fix
|
| 76 |
+
device=Config.DEVICE
|
| 77 |
+
).unsqueeze(0)
|
| 78 |
+
# --- END MODIFIED ---
|
| 79 |
+
|
| 80 |
# Create keypoint image
|
| 81 |
face_kps = draw_kps(processed_image, face_info['kps'])
|
| 82 |
|
|
|
|
| 95 |
self.mh.pipeline.set_ip_adapter_scale(0.0)
|
| 96 |
|
| 97 |
# We keep the guidance_end for pose low
|
| 98 |
+
control_guidance_end = [0.3, 0.6, 0.6]
|
| 99 |
|
| 100 |
# --- Seed/Generator Logic ---
|
| 101 |
if seed == -1 or seed is None:
|
|
|
|
| 110 |
prompt=final_prompt,
|
| 111 |
negative_prompt=negative_prompt,
|
| 112 |
image=processed_image, # Base img2img image
|
| 113 |
+
control_image=[face_kps, depth_map, lineart_map],
|
| 114 |
image_embeds=face_emb, # Face identity embedding
|
| 115 |
generator=generator,
|
| 116 |
|