John6666 commited on
Commit
f0ff983
1 Parent(s): 879fae2

Upload 5 files

Browse files
app.py CHANGED
@@ -53,8 +53,9 @@ It saves you the trouble of typing them in.<br>
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="", 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_half = gr.Checkbox(label="Half precision", value=True)
59
  vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
60
  scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
@@ -71,12 +72,12 @@ It saves you the trouble of typing them in.<br>
71
  run_button = gr.Button(value="Submit")
72
  repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
73
  output_md = gr.Markdown(label="Output")
74
- gr.DuplicateButton(value="Duplicate Space")
75
 
76
  gr.on(
77
  triggers=[run_button.click],
78
  fn=convert_url_to_diffusers_repo,
79
- inputs=[dl_url, repo_id, hf_token, civitai_key, repo_urls, is_half, vae, scheduler,
80
  lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s],
81
  outputs=[repo_urls, output_md],
82
  )
 
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")
 
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")
76
 
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
  )
convert_url_to_diffusers_sdxl.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_sdxl_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_sdxl(url, civitai_key="", half=True, vae=None, scheduler="Euler a", lora_dict={}, progress=gr.Progress(track_tqdm=True)):
209
  progress(0, desc="Start converting...")
210
  temp_dir = "."
211
  new_file = get_download_file(temp_dir, url, civitai_key)
@@ -225,6 +233,10 @@ def convert_url_to_diffusers_sdxl(url, civitai_key="", half=True, vae=None, sche
225
  pipe = StableDiffusionXLPipeline.from_single_file(new_file, use_safetensors=True, torch_dtype=torch.float16)
226
  else:
227
  pipe = StableDiffusionXLPipeline.from_single_file(new_file, use_safetensors=True)
 
 
 
 
228
 
229
  new_vae_file = ""
230
  if vae:
@@ -289,7 +301,7 @@ def create_diffusers_repo(new_repo_id, diffusers_folder, progress=gr.Progress(tr
289
  return url
290
 
291
 
292
- def convert_url_to_diffusers_repo(dl_url, new_repo_id, hf_token, civitai_key="", repo_urls=[], half=True, vae=None,
293
  scheduler="Euler a", lora1=None, lora1s=1.0, lora2=None, lora2s=1.0, lora3=None, lora3s=1.0,
294
  lora4=None, lora4s=1.0, lora5=None, lora5s=1.0, progress=gr.Progress(track_tqdm=True)):
295
  if hf_token and not os.environ.get("HF_TOKEN"): os.environ['HF_TOKEN'] = hf_token
@@ -304,7 +316,7 @@ def convert_url_to_diffusers_repo(dl_url, new_repo_id, hf_token, civitai_key="",
304
  return gr.update(value=repo_urls, choices=repo_urls), gr.update(value="")
305
  lora_dict = {lora1: lora1s, lora2: lora2s, lora3: lora3s, lora4: lora4s, lora5: lora5s}
306
  if None in lora_dict.keys(): del lora_dict[None]
307
- new_path = convert_url_to_diffusers_sdxl(dl_url, civitai_key, half, vae, scheduler, lora_dict)
308
  if not new_path: return ""
309
  repo_url = create_diffusers_repo(new_repo_id, new_path)
310
  if not repo_urls: repo_urls = []
 
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_sdxl(url, civitai_key="", is_upload_sf=False, half=True, vae=None, scheduler="Euler a", lora_dict={}, progress=gr.Progress(track_tqdm=True)):
217
  progress(0, desc="Start converting...")
218
  temp_dir = "."
219
  new_file = get_download_file(temp_dir, url, civitai_key)
 
233
  pipe = StableDiffusionXLPipeline.from_single_file(new_file, use_safetensors=True, torch_dtype=torch.float16)
234
  else:
235
  pipe = StableDiffusionXLPipeline.from_single_file(new_file, use_safetensors=True)
236
+ if is_upload_sf:
237
+ import shutil
238
+ shutil.move(str(Path(new_file).resolve()), str(Path(new_repo_name, Path(new_file).name).resolve()))
239
+
240
 
241
  new_vae_file = ""
242
  if vae:
 
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
 
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 = []
local/convert_url_to_diffusers_sdxl.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
  ---