Spaces:
Running
Running
Upload 4 files
Browse files
convert_url_to_diffusers_sdxl.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()
|
@@ -284,8 +286,6 @@ if __name__ == "__main__":
|
|
284 |
assert args.url is not None, "Must provide a URL!"
|
285 |
|
286 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
287 |
-
for k, v in lora_dict.items():
|
288 |
-
if k == None or k == "": del lora_dict[k]
|
289 |
|
290 |
if args.loras and Path(args.loras).exists():
|
291 |
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()
|
|
|
286 |
assert args.url is not None, "Must provide a URL!"
|
287 |
|
288 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
|
|
289 |
|
290 |
if args.loras and Path(args.loras).exists():
|
291 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
convert_url_to_diffusers_sdxl_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}")
|
@@ -312,8 +313,6 @@ def convert_url_to_diffusers_repo(dl_url, hf_user, hf_repo, hf_token, civitai_ke
|
|
312 |
if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
|
313 |
if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
|
314 |
lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
|
315 |
-
for k, v in lora_dict.items():
|
316 |
-
if k == None or k == "": del lora_dict[k]
|
317 |
new_path = convert_url_to_diffusers_sdxl(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict)
|
318 |
if not new_path: return ""
|
319 |
new_repo_id = f"{hf_user}/{Path(new_path).stem}"
|
@@ -359,8 +358,6 @@ if __name__ == "__main__":
|
|
359 |
assert args.url is not None, "Must provide a URL!"
|
360 |
|
361 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
362 |
-
for k, v in lora_dict.items():
|
363 |
-
if k == None or k == "": del lora_dict[k]
|
364 |
|
365 |
if args.loras and Path(args.loras).exists():
|
366 |
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}")
|
|
|
313 |
if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
|
314 |
if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
|
315 |
lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
|
|
|
|
|
316 |
new_path = convert_url_to_diffusers_sdxl(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict)
|
317 |
if not new_path: return ""
|
318 |
new_repo_id = f"{hf_user}/{Path(new_path).stem}"
|
|
|
358 |
assert args.url is not None, "Must provide a URL!"
|
359 |
|
360 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
|
|
361 |
|
362 |
if args.loras and Path(args.loras).exists():
|
363 |
for p in Path(args.loras).glob('**/*.safetensors'):
|
local/convert_url_to_diffusers_sdxl.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()
|
@@ -284,8 +286,6 @@ if __name__ == "__main__":
|
|
284 |
assert args.url is not None, "Must provide a URL!"
|
285 |
|
286 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
287 |
-
for k, v in lora_dict.items():
|
288 |
-
if k == None or k == "": del lora_dict[k]
|
289 |
|
290 |
if args.loras and Path(args.loras).exists():
|
291 |
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()
|
|
|
286 |
assert args.url is not None, "Must provide a URL!"
|
287 |
|
288 |
lora_dict = {args.lora1: args.lora1s, args.lora2: args.lora2s, args.lora3: args.lora3s, args.lora4: args.lora4s, args.lora5: args.lora5s}
|
|
|
|
|
289 |
|
290 |
if args.loras and Path(args.loras).exists():
|
291 |
for p in Path(args.loras).glob('**/*.safetensors'):
|