Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
models.py
CHANGED
|
@@ -176,65 +176,40 @@ def load_controlnets():
|
|
| 176 |
def load_sdxl_pipeline(controlnets):
|
| 177 |
"""
|
| 178 |
Load SDXL pipeline with InstantID support.
|
| 179 |
-
|
| 180 |
-
Following the working example from examplewithface.py
|
| 181 |
"""
|
| 182 |
print("Loading SDXL checkpoint with InstantID pipeline...")
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
except Exception as e:
|
| 216 |
-
print(f" [ERROR] Could not load InstantID pipeline: {e}")
|
| 217 |
-
import traceback
|
| 218 |
-
traceback.print_exc()
|
| 219 |
-
|
| 220 |
-
# Fallback to standard pipeline
|
| 221 |
-
print(" [WARNING] Falling back to standard SDXL pipeline (no InstantID)")
|
| 222 |
-
from diffusers import StableDiffusionXLControlNetImg2ImgPipeline
|
| 223 |
-
|
| 224 |
-
# Wrap in MultiControlNetModel for fallback too
|
| 225 |
-
if isinstance(controlnets, list) and len(controlnets) > 1:
|
| 226 |
-
from diffusers.models.controlnets.multicontrolnet import MultiControlNetModel
|
| 227 |
-
controlnet_for_pipeline = MultiControlNetModel(controlnets)
|
| 228 |
-
else:
|
| 229 |
-
controlnet_for_pipeline = controlnets[0] if isinstance(controlnets, list) else controlnets
|
| 230 |
-
|
| 231 |
-
pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 232 |
-
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 233 |
-
controlnet=controlnet_for_pipeline,
|
| 234 |
-
torch_dtype=dtype,
|
| 235 |
-
use_safetensors=True
|
| 236 |
-
).to(device)
|
| 237 |
-
return pipe, False
|
| 238 |
|
| 239 |
|
| 240 |
# Global variable to track LORA fusion state (like in working example)
|
|
|
|
| 176 |
def load_sdxl_pipeline(controlnets):
|
| 177 |
"""
|
| 178 |
Load SDXL pipeline with InstantID support.
|
| 179 |
+
EXACTLY following working example: from_pretrained with controlnet list
|
|
|
|
| 180 |
"""
|
| 181 |
print("Loading SDXL checkpoint with InstantID pipeline...")
|
| 182 |
+
|
| 183 |
+
# Load VAE (like working example line 128)
|
| 184 |
+
print("Loading VAE...")
|
| 185 |
+
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=dtype)
|
| 186 |
+
print(" [OK] VAE loaded")
|
| 187 |
+
|
| 188 |
+
# Load pipeline EXACTLY like working example (line 134-137)
|
| 189 |
+
# Uses from_pretrained, NOT from_single_file!
|
| 190 |
+
# Passes controlnet list directly, NO MultiControlNetModel wrapper!
|
| 191 |
+
print("Loading InstantID pipeline from_pretrained (like working example)...")
|
| 192 |
+
pipe = StableDiffusionXLInstantIDImg2ImgPipeline.from_pretrained(
|
| 193 |
+
"frankjoshua/albedobaseXL_v21",
|
| 194 |
+
vae=vae,
|
| 195 |
+
controlnet=controlnets, # Pass list directly [identitynet, depthnet]
|
| 196 |
+
torch_dtype=dtype
|
| 197 |
+
)
|
| 198 |
+
pipe = pipe.to(device)
|
| 199 |
+
print(" [OK] Pipeline loaded with from_pretrained")
|
| 200 |
+
|
| 201 |
+
# Load IP-Adapter weights for InstantID (like working example line 139)
|
| 202 |
+
print("Loading IP-Adapter for InstantID...")
|
| 203 |
+
ip_adapter_path = download_model_with_retry(
|
| 204 |
+
"InstantX/InstantID",
|
| 205 |
+
"ip-adapter.bin"
|
| 206 |
+
)
|
| 207 |
+
pipe.load_ip_adapter_instantid(ip_adapter_path)
|
| 208 |
+
pipe.set_ip_adapter_scale(0.8) # Initial scale like working example line 140
|
| 209 |
+
print(" [OK] IP-Adapter loaded (initial scale 0.8)")
|
| 210 |
+
|
| 211 |
+
print(" [OK] InstantID pipeline loaded successfully (matches working example)")
|
| 212 |
+
return pipe, True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
|
| 215 |
# Global variable to track LORA fusion state (like in working example)
|