John6666 commited on
Commit
2024d03
1 Parent(s): 4558fef

Upload 5 files

Browse files
app.py CHANGED
@@ -44,6 +44,7 @@ It saves you the trouble of typing them in.<br>
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_half = gr.Checkbox(label="Half precision", value=True)
48
  model_type = gr.Radio(label="Model type", choices=["v1", "v2"], value="v1")
49
  sample_size = gr.Radio(label="Sample size (px)", choices=[512, 768], value=768)
@@ -63,12 +64,12 @@ It saves you the trouble of typing them in.<br>
63
  run_button = gr.Button(value="Submit")
64
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
65
  output_md = gr.Markdown(label="Output")
66
- gr.DuplicateButton(value="Duplicate Space")
67
 
68
  gr.on(
69
  triggers=[run_button.click],
70
  fn=convert_url_to_diffusers_repo_sd,
71
- inputs=[dl_url, repo_id, hf_token, civitai_key, repo_urls, is_half, vae, scheduler,
72
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s,
73
  model_type, sample_size, ema],
74
  outputs=[repo_urls, output_md],
 
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)
 
64
  run_button = gr.Button(value="Submit")
65
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
66
  output_md = gr.Markdown(label="Output")
67
+ gr.DuplicateButton(value="Duplicate Space")
68
 
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],
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
  ---
convert_url_to_diffusers_sd_gr.py CHANGED
@@ -169,6 +169,10 @@ def save_readme_md(dir, url):
169
  if orig_name and orig_url:
170
  md = f"""---
171
  license: other
 
 
 
 
172
  tags:
173
  - text-to-image
174
  ---
@@ -177,6 +181,10 @@ Converted from [{orig_name}]({orig_url}).
177
  else:
178
  md = f"""---
179
  license: other
 
 
 
 
180
  tags:
181
  - text-to-image
182
  ---
@@ -205,7 +213,7 @@ def fuse_loras(pipe, lora_dict={}, temp_dir=".", civitai_key=""):
205
  pipe.unload_lora_weights()
206
 
207
 
208
- def convert_url_to_diffusers_sd(url, civitai_key="", half=True, vae=None, scheduler="Euler", lora_dict={},
209
  model_type="v1", sample_size=768, ema="ema", progress=gr.Progress(track_tqdm=True)):
210
  progress(0, desc="Start converting...")
211
  temp_dir = "."
@@ -264,6 +272,10 @@ def convert_url_to_diffusers_sd(url, civitai_key="", half=True, vae=None, schedu
264
  if Path(new_repo_name).exists():
265
  save_readme_md(new_repo_name, url)
266
 
 
 
 
 
267
  progress(1, desc="Converted.")
268
  return new_repo_name
269
 
@@ -300,7 +312,7 @@ def create_diffusers_repo(new_repo_id, diffusers_folder, progress=gr.Progress(tr
300
  return url
301
 
302
 
303
- def convert_url_to_diffusers_repo_sd(dl_url, new_repo_id, hf_token, civitai_key="", repo_urls=[], half=True, vae=None,
304
  scheduler="Euler", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
305
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0,
306
  model_type="v1", sample_size=768, ema="ema", progress=gr.Progress(track_tqdm=True)):
@@ -316,7 +328,7 @@ def convert_url_to_diffusers_repo_sd(dl_url, new_repo_id, hf_token, civitai_key=
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_sd(dl_url, civitai_key, half, vae, scheduler, lora_dict,
320
  model_type, sample_size, ema)
321
  if not new_path: return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
322
  repo_url = create_diffusers_repo(new_repo_id, new_path)
 
169
  if orig_name and orig_url:
170
  md = f"""---
171
  license: other
172
+ language:
173
+ - en
174
+ library_name: diffusers
175
+ pipeline_tag: text-to-image
176
  tags:
177
  - text-to-image
178
  ---
 
181
  else:
182
  md = f"""---
183
  license: other
184
+ language:
185
+ - en
186
+ library_name: diffusers
187
+ pipeline_tag: text-to-image
188
  tags:
189
  - text-to-image
190
  ---
 
213
  pipe.unload_lora_weights()
214
 
215
 
216
+ def convert_url_to_diffusers_sd(url, civitai_key="", is_upload_sf=False, half=True, vae=None, scheduler="Euler", lora_dict={},
217
  model_type="v1", sample_size=768, ema="ema", progress=gr.Progress(track_tqdm=True)):
218
  progress(0, desc="Start converting...")
219
  temp_dir = "."
 
272
  if Path(new_repo_name).exists():
273
  save_readme_md(new_repo_name, url)
274
 
275
+ if not is_repo_name(new_file) and is_upload_sf:
276
+ import shutil
277
+ shutil.move(str(Path(new_file).resolve()), str(Path(new_repo_name, Path(new_file).name).resolve()))
278
+
279
  progress(1, desc="Converted.")
280
  return new_repo_name
281
 
 
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)):
 
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)