Spaces:
Running
Running
Upload 4 files
Browse files
convert_url_to_diffusers_sd.py
CHANGED
@@ -198,6 +198,7 @@ def fuse_loras(pipe, civitai_key="", lora_dict={}, temp_dir="."):
|
|
198 |
a_list = []
|
199 |
w_list = []
|
200 |
for k, v in lora_dict.items():
|
|
|
201 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
202 |
if not new_lora_file or not Path(new_lora_file).exists():
|
203 |
print(f"LoRA not found: {k}")
|
@@ -206,7 +207,8 @@ def fuse_loras(pipe, civitai_key="", lora_dict={}, temp_dir="."):
|
|
206 |
a_name = Path(new_lora_file).stem
|
207 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
208 |
a_list.append(a_name)
|
209 |
-
w_list.append(v)
|
|
|
210 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
211 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
212 |
pipe.unload_lora_weights()
|
@@ -300,7 +302,6 @@ if __name__ == "__main__":
|
|
300 |
assert args.url is not None, "Must provide a URL!"
|
301 |
|
302 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
303 |
-
if None in lora_dict.keys(): del lora_dict[None]
|
304 |
|
305 |
if args.loras and Path(args.loras).exists():
|
306 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
|
|
198 |
a_list = []
|
199 |
w_list = []
|
200 |
for k, v in lora_dict.items():
|
201 |
+
if not k: continue
|
202 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
203 |
if not new_lora_file or not Path(new_lora_file).exists():
|
204 |
print(f"LoRA not found: {k}")
|
|
|
207 |
a_name = Path(new_lora_file).stem
|
208 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
209 |
a_list.append(a_name)
|
210 |
+
w_list.append(v)
|
211 |
+
if not a_list: return
|
212 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
213 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
214 |
pipe.unload_lora_weights()
|
|
|
302 |
assert args.url is not None, "Must provide a URL!"
|
303 |
|
304 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
305 |
|
306 |
if args.loras and Path(args.loras).exists():
|
307 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
convert_url_to_diffusers_sd_gr.py
CHANGED
@@ -199,6 +199,7 @@ def fuse_loras(pipe, lora_dict={}, temp_dir=".", civitai_key=""):
|
|
199 |
a_list = []
|
200 |
w_list = []
|
201 |
for k, v in lora_dict.items():
|
|
|
202 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
203 |
if not new_lora_file or not Path(new_lora_file).exists():
|
204 |
print(f"LoRA not found: {k}")
|
@@ -207,7 +208,8 @@ def fuse_loras(pipe, lora_dict={}, temp_dir=".", civitai_key=""):
|
|
207 |
a_name = Path(new_lora_file).stem
|
208 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
209 |
a_list.append(a_name)
|
210 |
-
w_list.append(v)
|
|
|
211 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
212 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
213 |
pipe.unload_lora_weights()
|
@@ -323,7 +325,6 @@ def convert_url_to_diffusers_repo_sd(dl_url, hf_user, hf_repo, hf_token, civitai
|
|
323 |
if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
|
324 |
if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
|
325 |
lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
|
326 |
-
if None in lora_dict.keys(): del lora_dict[None]
|
327 |
new_path = convert_url_to_diffusers_sd(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict,
|
328 |
model_type, sample_size, ema)
|
329 |
if not new_path: return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
|
@@ -373,7 +374,6 @@ if __name__ == "__main__":
|
|
373 |
assert args.url is not None, "Must provide a URL!"
|
374 |
|
375 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
376 |
-
if None in lora_dict.keys(): del lora_dict[None]
|
377 |
|
378 |
if args.loras and Path(args.loras).exists():
|
379 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
|
|
199 |
a_list = []
|
200 |
w_list = []
|
201 |
for k, v in lora_dict.items():
|
202 |
+
if not k: continue
|
203 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
204 |
if not new_lora_file or not Path(new_lora_file).exists():
|
205 |
print(f"LoRA not found: {k}")
|
|
|
208 |
a_name = Path(new_lora_file).stem
|
209 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
210 |
a_list.append(a_name)
|
211 |
+
w_list.append(v)
|
212 |
+
if not a_list: return
|
213 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
214 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
215 |
pipe.unload_lora_weights()
|
|
|
325 |
if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
|
326 |
if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
|
327 |
lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
|
|
|
328 |
new_path = convert_url_to_diffusers_sd(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict,
|
329 |
model_type, sample_size, ema)
|
330 |
if not new_path: return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
|
|
|
374 |
assert args.url is not None, "Must provide a URL!"
|
375 |
|
376 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
377 |
|
378 |
if args.loras and Path(args.loras).exists():
|
379 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
local/convert_url_to_diffusers_sd.py
CHANGED
@@ -198,6 +198,7 @@ def fuse_loras(pipe, civitai_key="", lora_dict={}, temp_dir="."):
|
|
198 |
a_list = []
|
199 |
w_list = []
|
200 |
for k, v in lora_dict.items():
|
|
|
201 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
202 |
if not new_lora_file or not Path(new_lora_file).exists():
|
203 |
print(f"LoRA not found: {k}")
|
@@ -206,7 +207,8 @@ def fuse_loras(pipe, civitai_key="", lora_dict={}, temp_dir="."):
|
|
206 |
a_name = Path(new_lora_file).stem
|
207 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
208 |
a_list.append(a_name)
|
209 |
-
w_list.append(v)
|
|
|
210 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
211 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
212 |
pipe.unload_lora_weights()
|
@@ -300,7 +302,6 @@ if __name__ == "__main__":
|
|
300 |
assert args.url is not None, "Must provide a URL!"
|
301 |
|
302 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
303 |
-
if None in lora_dict.keys(): del lora_dict[None]
|
304 |
|
305 |
if args.loras and Path(args.loras).exists():
|
306 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
|
|
198 |
a_list = []
|
199 |
w_list = []
|
200 |
for k, v in lora_dict.items():
|
201 |
+
if not k: continue
|
202 |
new_lora_file = get_download_file(temp_dir, k, civitai_key)
|
203 |
if not new_lora_file or not Path(new_lora_file).exists():
|
204 |
print(f"LoRA not found: {k}")
|
|
|
207 |
a_name = Path(new_lora_file).stem
|
208 |
pipe.load_lora_weights(new_lora_file, weight_name = w_name, adapter_name = a_name)
|
209 |
a_list.append(a_name)
|
210 |
+
w_list.append(v)
|
211 |
+
if not a_list: return
|
212 |
pipe.set_adapters(a_list, adapter_weights=w_list)
|
213 |
pipe.fuse_lora(adapter_names=a_list, lora_scale=1.0)
|
214 |
pipe.unload_lora_weights()
|
|
|
302 |
assert args.url is not None, "Must provide a URL!"
|
303 |
|
304 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
305 |
|
306 |
if args.loras and Path(args.loras).exists():
|
307 |
for p in Path(args.loras).glob('**/*.safetensors'):
|