Spaces:
Running
on
Zero
Running
on
Zero
Update model.py
Browse files
model.py
CHANGED
|
@@ -129,23 +129,24 @@ class ModelHandler:
|
|
| 129 |
# 5. Load Adapters
|
| 130 |
print("Loading Adapters...")
|
| 131 |
|
| 132 |
-
#
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
| 136 |
hf_hub_download(
|
| 137 |
-
repo_id=Config.
|
| 138 |
-
filename=
|
| 139 |
local_dir="./models",
|
| 140 |
local_dir_use_symlinks=False
|
| 141 |
)
|
| 142 |
-
self.pipeline.
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
print("Loading TCD-SDXL-LoRA...")
|
| 149 |
tcd_lora_filename = "pytorch_lora_weights.safetensors"
|
| 150 |
tcd_lora_path = os.path.join("./models", tcd_lora_filename)
|
| 151 |
if not os.path.exists(tcd_lora_path):
|
|
@@ -155,28 +156,23 @@ class ModelHandler:
|
|
| 155 |
local_dir="./models",
|
| 156 |
local_dir_use_symlinks=False
|
| 157 |
)
|
| 158 |
-
|
| 159 |
-
self.pipeline.
|
| 160 |
-
print(" [OK] TCD LoRA
|
| 161 |
|
| 162 |
-
# 5c.
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
if not os.path.exists(
|
| 166 |
hf_hub_download(
|
| 167 |
-
repo_id=Config.
|
| 168 |
-
filename=
|
| 169 |
local_dir="./models",
|
| 170 |
local_dir_use_symlinks=False
|
| 171 |
)
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
print(" [OK] Style LoRA loaded.")
|
| 175 |
|
| 176 |
-
# 6. Set Adapter Weights (TCD + Style)
|
| 177 |
-
# This correctly activates both LoRAs simultaneously
|
| 178 |
-
print(f"Setting adapter weights: TCD (1.0), Style ({Config.LORA_STRENGTH})")
|
| 179 |
-
self.pipeline.set_adapters(["tcd", "style"], adapter_weights=[1.0, Config.LORA_STRENGTH])
|
| 180 |
# --- END FIX ---
|
| 181 |
|
| 182 |
# 7. Load Preprocessors
|
|
|
|
| 129 |
# 5. Load Adapters
|
| 130 |
print("Loading Adapters...")
|
| 131 |
|
| 132 |
+
# --- FIX: We must FUSE LoRAs in order to avoid TCD/Style adapter conflict ---
|
| 133 |
+
|
| 134 |
+
# 5a. Load and Fuse Style LoRA (lucasart)
|
| 135 |
+
print(f"Loading and Fusing Style LoRA ({Config.LORA_FILENAME})...")
|
| 136 |
+
style_lora_path = os.path.join("./models", Config.LORA_FILENAME)
|
| 137 |
+
if not os.path.exists(style_lora_path):
|
| 138 |
hf_hub_download(
|
| 139 |
+
repo_id=Config.REPO_ID,
|
| 140 |
+
filename=Config.LORA_FILENAME,
|
| 141 |
local_dir="./models",
|
| 142 |
local_dir_use_symlinks=False
|
| 143 |
)
|
| 144 |
+
self.pipeline.load_lora_weights("./models", weight_name=Config.LORA_FILENAME)
|
| 145 |
+
self.pipeline.fuse_lora(lora_scale=Config.LORA_STRENGTH)
|
| 146 |
+
print(" [OK] Style LoRA fused.")
|
| 147 |
+
|
| 148 |
+
# 5b. Load and Fuse TCD LoRA (for speed)
|
| 149 |
+
print("Loading and Fusing TCD-SDXL-LoRA...")
|
|
|
|
| 150 |
tcd_lora_filename = "pytorch_lora_weights.safetensors"
|
| 151 |
tcd_lora_path = os.path.join("./models", tcd_lora_filename)
|
| 152 |
if not os.path.exists(tcd_lora_path):
|
|
|
|
| 156 |
local_dir="./models",
|
| 157 |
local_dir_use_symlinks=False
|
| 158 |
)
|
| 159 |
+
self.pipeline.load_lora_weights("./models", weight_name=tcd_lora_filename)
|
| 160 |
+
self.pipeline.fuse_lora(lora_scale=1.0) # TCD must be fused at 1.0
|
| 161 |
+
print(" [OK] TCD LoRA fused.")
|
| 162 |
|
| 163 |
+
# 5c. Load IP-Adapter (for InstantID) - *Must be loaded AFTER fusing*
|
| 164 |
+
ip_adapter_filename = "ip-adapter.bin"
|
| 165 |
+
ip_adapter_local_path = os.path.join("./models", ip_adapter_filename)
|
| 166 |
+
if not os.path.exists(ip_adapter_local_path):
|
| 167 |
hf_hub_download(
|
| 168 |
+
repo_id=Config.INSTANTID_REPO,
|
| 169 |
+
filename=ip_adapter_filename,
|
| 170 |
local_dir="./models",
|
| 171 |
local_dir_use_symlinks=False
|
| 172 |
)
|
| 173 |
+
self.pipeline.load_ip_adapter_instantid(ip_adapter_local_path)
|
| 174 |
+
print(" [OK] IP-Adapter loaded.")
|
|
|
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
# --- END FIX ---
|
| 177 |
|
| 178 |
# 7. Load Preprocessors
|