John6666 commited on
Commit
5519c1a
1 Parent(s): d9ae74a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +21 -18
  2. convert_url_to_diffusers_sdxl_gr.py +11 -5
app.py CHANGED
@@ -44,32 +44,35 @@ It saves you the trouble of typing them in.<br>
44
  - Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
45
  - Input a model download url from the Hub or Civitai or other sites.
46
  - If you want to download a model from Civitai, paste a Civitai API Key.
47
- - Input your new repo name. e.g. 'yourid/newrepo'.
 
48
  - Set the parameters. If not sure, just use the defaults.
49
  - Click "Submit".
50
  - Patiently wait until the output changes.
51
  """
52
  )
53
  with gr.Column():
54
- dl_url = gr.Textbox(label="URL to download", placeholder="https://...", value="", max_lines=1)
55
- repo_id = gr.Textbox(label="Your New Repo ID", placeholder="author/model", value="", max_lines=1)
 
56
  hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
57
  civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
58
  is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
59
- is_half = gr.Checkbox(label="Half precision", value=True)
60
- vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
61
- scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
62
- lora1 = gr.Dropdown(label="LoRA1", choices=loras, value="", allow_custom_value=True)
63
- lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
64
- lora2 = gr.Dropdown(label="LoRA2", choices=loras, value="", allow_custom_value=True)
65
- lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
66
- lora3 = gr.Dropdown(label="LoRA3", choices=loras, value="", allow_custom_value=True)
67
- lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
68
- lora4 = gr.Dropdown(label="LoRA4", choices=loras, value="", allow_custom_value=True)
69
- lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
70
- lora5 = gr.Dropdown(label="LoRA5", choices=loras, value="", allow_custom_value=True)
71
- lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
72
- run_button = gr.Button(value="Submit")
 
73
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
74
  output_md = gr.Markdown(label="Output")
75
  gr.DuplicateButton(value="Duplicate Space")
@@ -77,7 +80,7 @@ It saves you the trouble of typing them in.<br>
77
  gr.on(
78
  triggers=[run_button.click],
79
  fn=convert_url_to_diffusers_repo,
80
- inputs=[dl_url, repo_id, hf_token, civitai_key, is_upload_sf, repo_urls, is_half, vae, scheduler,
81
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s],
82
  outputs=[repo_urls, output_md],
83
  )
 
44
  - Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
45
  - Input a model download url from the Hub or Civitai or other sites.
46
  - If you want to download a model from Civitai, paste a Civitai API Key.
47
+ - Input your HF user ID. e.g. 'yourid'.
48
+ - Input your new repo name. If empty, auto-complete. e.g. 'newrepo'.
49
  - Set the parameters. If not sure, just use the defaults.
50
  - Click "Submit".
51
  - Patiently wait until the output changes.
52
  """
53
  )
54
  with gr.Column():
55
+ dl_url = gr.Textbox(label="URL to download", placeholder="https://huggingface.co/bluepen5805/blue_pencil-XL/blob/main/blue_pencil-XL-v7.0.0.safetensors", value="", max_lines=1)
56
+ hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value="", max_lines=1)
57
+ hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value="", max_lines=1)
58
  hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
59
  civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
60
  is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
61
+ with gr.Accordion("Advanced settings"):
62
+ is_half = gr.Checkbox(label="Half precision", value=True)
63
+ vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
64
+ scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
65
+ lora1 = gr.Dropdown(label="LoRA1", choices=loras, value="", allow_custom_value=True)
66
+ lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
67
+ lora2 = gr.Dropdown(label="LoRA2", choices=loras, value="", allow_custom_value=True)
68
+ lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
69
+ lora3 = gr.Dropdown(label="LoRA3", choices=loras, value="", allow_custom_value=True)
70
+ lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
71
+ lora4 = gr.Dropdown(label="LoRA4", choices=loras, value="", allow_custom_value=True)
72
+ lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
73
+ lora5 = gr.Dropdown(label="LoRA5", choices=loras, value="", allow_custom_value=True)
74
+ lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
75
+ run_button = gr.Button(value="Submit")
76
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
77
  output_md = gr.Markdown(label="Output")
78
  gr.DuplicateButton(value="Duplicate Space")
 
80
  gr.on(
81
  triggers=[run_button.click],
82
  fn=convert_url_to_diffusers_repo,
83
+ inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_upload_sf, repo_urls, is_half, vae, scheduler,
84
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s],
85
  outputs=[repo_urls, output_md],
86
  )
convert_url_to_diffusers_sdxl_gr.py CHANGED
@@ -301,11 +301,21 @@ def create_diffusers_repo(new_repo_id, diffusers_folder, progress=gr.Progress(tr
301
  return url
302
 
303
 
304
- def convert_url_to_diffusers_repo(dl_url, new_repo_id, hf_token, civitai_key="", is_upload_sf=False, repo_urls=[], half=True, vae=None,
305
  scheduler="Euler a", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
306
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
307
  if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
308
  if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
 
 
 
 
 
 
309
  if not is_repo_name(new_repo_id):
310
  print(f"Invalid repo name: {new_repo_id}")
311
  progress(1, desc=f"Invalid repo name: {new_repo_id}")
@@ -314,10 +324,6 @@ def convert_url_to_diffusers_repo(dl_url, new_repo_id, hf_token, civitai_key="",
314
  print(f"Repo already exists: {new_repo_id}")
315
  progress(1, desc=f"Repo already exists: {new_repo_id}")
316
  return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
317
- lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
318
- if None in lora_dict.keys(): del lora_dict[None]
319
- new_path = convert_url_to_diffusers_sdxl(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict)
320
- if not new_path: return ""
321
  repo_url = create_diffusers_repo(new_repo_id, new_path)
322
  if not repo_urls: repo_urls = []
323
  repo_urls.append(repo_url)
 
301
  return url
302
 
303
 
304
+ def convert_url_to_diffusers_repo(dl_url, hf_user, hf_repo, hf_token, civitai_key="", is_upload_sf=False, repo_urls=[], half=True, vae=None,
305
  scheduler="Euler a", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
306
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0, progress=gr.Progress(track_tqdm=True)):
307
+ if not hf_user:
308
+ print(f"Invalid user name: {hf_user}")
309
+ progress(1, desc=f"Invalid user name: {hf_user}")
310
+ return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
311
  if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
312
  if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
313
+ lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
314
+ if None in lora_dict.keys(): del lora_dict[None]
315
+ new_path = convert_url_to_diffusers_sdxl(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict)
316
+ if not new_path: return ""
317
+ new_repo_id = f"{hf_user}/{Path(new_path).stem}"
318
+ if hf_repo != "": new_repo_id = f"{hf_user}/{hf_repo}"
319
  if not is_repo_name(new_repo_id):
320
  print(f"Invalid repo name: {new_repo_id}")
321
  progress(1, desc=f"Invalid repo name: {new_repo_id}")
 
324
  print(f"Repo already exists: {new_repo_id}")
325
  progress(1, desc=f"Repo already exists: {new_repo_id}")
326
  return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
 
 
 
 
327
  repo_url = create_diffusers_repo(new_repo_id, new_path)
328
  if not repo_urls: repo_urls = []
329
  repo_urls.append(repo_url)