John6666 commited on
Commit
29cdb8f
·
verified ·
1 Parent(s): 2024d03

Upload 5 files

Browse files
app.py CHANGED
@@ -33,34 +33,37 @@ It saves you the trouble of typing them in.<br>
33
  - Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
34
  - Input a model download url from the Hub or Civitai or other sites.
35
  - If you want to download a model from Civitai, paste a Civitai API Key.
36
- - Input your new repo name. e.g. 'yourid/newrepo'.
 
37
  - Set the parameters. If not sure, just use the defaults.
38
  - Click "Submit".
39
  - Patiently wait until the output changes.
40
  """
41
  )
42
  with gr.Column():
43
- dl_url = gr.Textbox(label="URL to download", placeholder="https://...", value="", max_lines=1)
44
- repo_id = gr.Textbox(label="Your New Repo ID", placeholder="author/model", value="", max_lines=1)
45
- hf_token = gr.Textbox(label="Your HF write token", placeholder="", value="", max_lines=1)
 
46
  civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
47
  is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
48
- is_half = gr.Checkbox(label="Half precision", value=True)
49
- model_type = gr.Radio(label="Model type", choices=["v1", "v2"], value="v1")
50
- sample_size = gr.Radio(label="Sample size (px)", choices=[512, 768], value=768)
51
- ema = gr.Radio(label="Extract EMA or non-EMA?", choices=["ema", "non-ema"], value="ema")
52
- vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
53
- scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler")
54
- lora1 = gr.Dropdown(label="LoRA1", choices=loras, value="", allow_custom_value=True)
55
- lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
56
- lora2 = gr.Dropdown(label="LoRA2", choices=loras, value="", allow_custom_value=True)
57
- lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
58
- lora3 = gr.Dropdown(label="LoRA3", choices=loras, value="", allow_custom_value=True)
59
- lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
60
- lora4 = gr.Dropdown(label="LoRA4", choices=loras, value="", allow_custom_value=True)
61
- lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
62
- lora5 = gr.Dropdown(label="LoRA5", choices=loras, value="", allow_custom_value=True)
63
- lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
 
64
  run_button = gr.Button(value="Submit")
65
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
66
  output_md = gr.Markdown(label="Output")
@@ -69,7 +72,7 @@ It saves you the trouble of typing them in.<br>
69
  gr.on(
70
  triggers=[run_button.click],
71
  fn=convert_url_to_diffusers_repo_sd,
72
- inputs=[dl_url, repo_id, hf_token, civitai_key, is_upload_sf, repo_urls, is_half, vae, scheduler,
73
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s,
74
  model_type, sample_size, ema],
75
  outputs=[repo_urls, output_md],
 
33
  - Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
34
  - Input a model download url from the Hub or Civitai or other sites.
35
  - If you want to download a model from Civitai, paste a Civitai API Key.
36
+ - Input your HF user ID. e.g. 'yourid'.
37
+ - Input your new repo name. If empty, auto-complete. e.g. 'newrepo'.
38
  - Set the parameters. If not sure, just use the defaults.
39
  - Click "Submit".
40
  - Patiently wait until the output changes.
41
  """
42
  )
43
  with gr.Column():
44
+ dl_url = gr.Textbox(label="URL to download", placeholder="https://huggingface.co/SG161222/RealVisXL_V4.0/blob/main/RealVisXL_V4.0.safetensors", value="", max_lines=1)
45
+ hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value="", max_lines=1)
46
+ hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value="", max_lines=1)
47
+ hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
48
  civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
49
  is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
50
+ with gr.Accordion("Advanced settings", open=False):
51
+ is_half = gr.Checkbox(label="Half precision", value=True)
52
+ model_type = gr.Radio(label="Model type", choices=["v1", "v2"], value="v1")
53
+ sample_size = gr.Radio(label="Sample size (px)", choices=[512, 768], value=768)
54
+ ema = gr.Radio(label="Extract EMA or non-EMA?", choices=["ema", "non-ema"], value="ema")
55
+ vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
56
+ scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler")
57
+ lora1 = gr.Dropdown(label="LoRA1", choices=loras, value="", allow_custom_value=True)
58
+ lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
59
+ lora2 = gr.Dropdown(label="LoRA2", choices=loras, value="", allow_custom_value=True)
60
+ lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
61
+ lora3 = gr.Dropdown(label="LoRA3", choices=loras, value="", allow_custom_value=True)
62
+ lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
63
+ lora4 = gr.Dropdown(label="LoRA4", choices=loras, value="", allow_custom_value=True)
64
+ lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
65
+ lora5 = gr.Dropdown(label="LoRA5", choices=loras, value="", allow_custom_value=True)
66
+ lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
67
  run_button = gr.Button(value="Submit")
68
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
69
  output_md = gr.Markdown(label="Output")
 
72
  gr.on(
73
  triggers=[run_button.click],
74
  fn=convert_url_to_diffusers_repo_sd,
75
+ inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_upload_sf, repo_urls, is_half, vae, scheduler,
76
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s,
77
  model_type, sample_size, ema],
78
  outputs=[repo_urls, output_md],
convert_url_to_diffusers_sd_gr.py CHANGED
@@ -312,12 +312,23 @@ def create_diffusers_repo(new_repo_id, diffusers_folder, progress=gr.Progress(tr
312
  return url
313
 
314
 
315
- def convert_url_to_diffusers_repo_sd(dl_url, new_repo_id, hf_token, civitai_key="", is_upload_sf=False, repo_urls=[], half=True, vae=None,
316
  scheduler="Euler", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
317
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0,
318
  model_type="v1", sample_size=768, ema="ema", progress=gr.Progress(track_tqdm=True)):
 
 
 
 
319
  if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
320
  if not civitai_key and os.environ.get("CIVITAI_API_KEY"): civitai_key = os.environ.get("CIVITAI_API_KEY")
 
 
 
 
 
 
 
321
  if not is_repo_name(new_repo_id):
322
  print(f"Invalid repo name: {new_repo_id}")
323
  progress(1, desc=f"Invalid repo name: {new_repo_id}")
@@ -326,11 +337,6 @@ def convert_url_to_diffusers_repo_sd(dl_url, new_repo_id, hf_token, civitai_key=
326
  print(f"Repo already exists: {new_repo_id}")
327
  progress(1, desc=f"Repo already exists: {new_repo_id}")
328
  return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
329
- lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
330
- if None in lora_dict.keys(): del lora_dict[None]
331
- new_path = convert_url_to_diffusers_sd(dl_url, civitai_key, is_upload_sf, half, vae, scheduler, lora_dict,
332
- model_type, sample_size, ema)
333
- if not new_path: return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
334
  repo_url = create_diffusers_repo(new_repo_id, new_path)
335
  if not repo_urls: repo_urls = []
336
  repo_urls.append(repo_url)
 
312
  return url
313
 
314
 
315
+ def convert_url_to_diffusers_repo_sd(dl_url, hf_user, hf_repo, hf_token, civitai_key="", is_upload_sf=False, repo_urls=[], half=True, vae=None,
316
  scheduler="Euler", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
317
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0,
318
  model_type="v1", sample_size=768, ema="ema", progress=gr.Progress(track_tqdm=True)):
319
+ if not hf_user:
320
+ print(f"Invalid user name: {hf_user}")
321
+ progress(1, desc=f"Invalid user name: {hf_user}")
322
+ return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
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="")
330
+ new_repo_id = f"{hf_user}/{Path(new_path).stem}"
331
+ if hf_repo != "": new_repo_id = f"{hf_user}/{hf_repo}"
332
  if not is_repo_name(new_repo_id):
333
  print(f"Invalid repo name: {new_repo_id}")
334
  progress(1, desc=f"Invalid repo name: {new_repo_id}")
 
337
  print(f"Repo already exists: {new_repo_id}")
338
  progress(1, desc=f"Repo already exists: {new_repo_id}")
339
  return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
 
 
 
 
 
340
  repo_url = create_diffusers_repo(new_repo_id, new_path)
341
  if not repo_urls: repo_urls = []
342
  repo_urls.append(repo_url)
local/convert_url_to_diffusers_sd.py CHANGED
@@ -168,6 +168,10 @@ def save_readme_md(dir, url):
168
  if orig_name and orig_url:
169
  md = f"""---
170
  license: other
 
 
 
 
171
  tags:
172
  - text-to-image
173
  ---
@@ -176,6 +180,10 @@ Converted from [{orig_name}]({orig_url}).
176
  else:
177
  md = f"""---
178
  license: other
 
 
 
 
179
  tags:
180
  - text-to-image
181
  ---
 
168
  if orig_name and orig_url:
169
  md = f"""---
170
  license: other
171
+ language:
172
+ - en
173
+ library_name: diffusers
174
+ pipeline_tag: text-to-image
175
  tags:
176
  - text-to-image
177
  ---
 
180
  else:
181
  md = f"""---
182
  license: other
183
+ language:
184
+ - en
185
+ library_name: diffusers
186
+ pipeline_tag: text-to-image
187
  tags:
188
  - text-to-image
189
  ---