TheAIBoi commited on
Commit
b4fcb00
·
verified ·
1 Parent(s): e3b778a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -120,11 +120,10 @@ def infer(
120
  prompt,
121
  negative_prompt,
122
  style,
123
- # Removed general img2img reference as we are specializing
124
- input_image_pose, # New: for ControlNet OpenPose
125
- pose_strength, # New: strength for ControlNet
126
- input_image_face, # New: for IP-Adapter Face
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
- ip_adapter_image_embeddings = None # Will store the face embeddings
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
- if input_image_face and pipe.has_lora_weights("ip_adapter"): # Check if IP-Adapter was loaded successfully
157
- # For IP-Adapter FaceID, the pipeline itself usually handles embedding extraction
158
- # You just pass the image directly.
159
- # The scale is set before the call.
160
  pipe.set_ip_adapter_scale(face_fidelity)
161
- # ip_adapter_image_embeddings = pipe.encode_ip_adapter_image(input_image_face) # If you need to manually encode
162
- # Often, you just pass the image to the main call directly if IP-Adapter is loaded.
163
-
164
- # --- END NEW INPUT PREPARATION ---
 
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, # Pass processed pose image(s) if available
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=input_image_face if input_image_face else None, # Pass the raw face image for IP-Adapter
175
- # ip_adapter_image_embeds=ip_adapter_image_embeddings, # Use this if you pre-encode
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,