Update app.py
Browse files
app.py
CHANGED
@@ -120,11 +120,10 @@ def infer(
|
|
120 |
prompt,
|
121 |
negative_prompt,
|
122 |
style,
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
face_fidelity, # New: fidelity/strength for IP-Adapter
|
128 |
seed,
|
129 |
randomize_seed,
|
130 |
width,
|
@@ -138,41 +137,35 @@ def infer(
|
|
138 |
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
139 |
generator = torch.Generator().manual_seed(seed)
|
140 |
|
141 |
-
# --- NEW: Prepare ControlNet and IP-Adapter inputs ---
|
142 |
controlnet_images = []
|
143 |
controlnet_conditioning_scales = []
|
144 |
controlnet_models_to_use = []
|
145 |
-
|
146 |
-
|
147 |
# Process Pose Reference
|
148 |
if input_image_pose:
|
149 |
-
# Preprocess the image to get the OpenPose skeleton
|
150 |
processed_pose_image = openpose_detector(input_image_pose)
|
151 |
controlnet_images.append(processed_pose_image)
|
152 |
controlnet_conditioning_scales.append(pose_strength)
|
153 |
controlnet_models_to_use.append(controlnet_openpose)
|
154 |
|
155 |
# Process Face Reference (IP-Adapter)
|
156 |
-
|
157 |
-
|
158 |
-
# You just pass the image directly.
|
159 |
-
# The scale is set before the call.
|
160 |
pipe.set_ip_adapter_scale(face_fidelity)
|
161 |
-
|
162 |
-
#
|
163 |
-
|
164 |
-
|
|
|
165 |
|
166 |
-
# Adjusting the pipe call to use ControlNet and IP-Adapter
|
167 |
-
# Note: If no reference images are provided, it will fall back to text-to-image.
|
168 |
image = pipe(
|
169 |
prompt=prompt,
|
170 |
negative_prompt=negative_prompt,
|
171 |
-
image=controlnet_images if controlnet_images else None,
|
172 |
controlnet_conditioning_scale=controlnet_conditioning_scales if controlnet_conditioning_scales else None,
|
173 |
controlnet=controlnet_models_to_use if controlnet_models_to_use else None,
|
174 |
-
ip_adapter_image
|
175 |
-
|
176 |
guidance_scale=guidance_scale,
|
177 |
num_inference_steps=num_inference_steps,
|
178 |
width=width,
|
|
|
120 |
prompt,
|
121 |
negative_prompt,
|
122 |
style,
|
123 |
+
input_image_pose,
|
124 |
+
pose_strength,
|
125 |
+
input_image_face,
|
126 |
+
face_fidelity,
|
|
|
127 |
seed,
|
128 |
randomize_seed,
|
129 |
width,
|
|
|
137 |
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
138 |
generator = torch.Generator().manual_seed(seed)
|
139 |
|
|
|
140 |
controlnet_images = []
|
141 |
controlnet_conditioning_scales = []
|
142 |
controlnet_models_to_use = []
|
143 |
+
|
|
|
144 |
# Process Pose Reference
|
145 |
if input_image_pose:
|
|
|
146 |
processed_pose_image = openpose_detector(input_image_pose)
|
147 |
controlnet_images.append(processed_pose_image)
|
148 |
controlnet_conditioning_scales.append(pose_strength)
|
149 |
controlnet_models_to_use.append(controlnet_openpose)
|
150 |
|
151 |
# Process Face Reference (IP-Adapter)
|
152 |
+
# CORRECTED LINE HERE: Use the 'ip_adapter_loaded' flag
|
153 |
+
if input_image_face and ip_adapter_loaded: # Use the flag to check if IP-Adapter loaded successfully
|
|
|
|
|
154 |
pipe.set_ip_adapter_scale(face_fidelity)
|
155 |
+
else:
|
156 |
+
# If no face input or IP-Adapter failed to load, ensure scale is reset or not applied
|
157 |
+
# This check is for the general 'lora_scale' attribute which IP-Adapter uses
|
158 |
+
if hasattr(pipe, 'lora_scale') and pipe.lora_scale is not None:
|
159 |
+
pipe.set_ip_adapter_scale(0.0) # Reset scale to 0.0
|
160 |
|
|
|
|
|
161 |
image = pipe(
|
162 |
prompt=prompt,
|
163 |
negative_prompt=negative_prompt,
|
164 |
+
image=controlnet_images if controlnet_images else None,
|
165 |
controlnet_conditioning_scale=controlnet_conditioning_scales if controlnet_conditioning_scales else None,
|
166 |
controlnet=controlnet_models_to_use if controlnet_models_to_use else None,
|
167 |
+
# Only pass ip_adapter_image if there's an input_image_face AND the IP-Adapter was successfully loaded
|
168 |
+
ip_adapter_image=input_image_face if input_image_face and ip_adapter_loaded else None,
|
169 |
guidance_scale=guidance_scale,
|
170 |
num_inference_steps=num_inference_steps,
|
171 |
width=width,
|