Upload 5 files
Browse files- app.py +25 -106
- convert_repo_to_safetensors_gr.py +3 -2
app.py
CHANGED
@@ -1,116 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
)
|
6 |
-
|
7 |
-
vaes = [
|
8 |
-
"",
|
9 |
-
"https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl.vae.safetensors",
|
10 |
-
"https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/blob/main/sdxl_vae-fp16fix-blessed.safetensors",
|
11 |
-
"https://huggingface.co/John6666/safetensors_converting_test/blob/main/xlVAEC_e7.safetensors",
|
12 |
-
"https://huggingface.co/John6666/safetensors_converting_test/blob/main/xlVAEC_f1.safetensors",
|
13 |
-
]
|
14 |
-
loras = [
|
15 |
-
"",
|
16 |
-
"https://huggingface.co/SPO-Diffusion-Models/SPO-SDXL_4k-p_10ep_LoRA/blob/main/spo_sdxl_10ep_4k-data_lora_diffusers.safetensors",
|
17 |
-
"https://huggingface.co/wangfuyun/PCM_Weights/blob/main/sdxl/pcm_sdxl_smallcfg_2step_converted.safetensors",
|
18 |
-
"https://huggingface.co/wangfuyun/PCM_Weights/blob/main/sdxl/pcm_sdxl_smallcfg_4step_converted.safetensors",
|
19 |
-
"https://huggingface.co/wangfuyun/PCM_Weights/blob/main/sdxl/pcm_sdxl_smallcfg_8step_converted.safetensors",
|
20 |
-
"https://huggingface.co/wangfuyun/PCM_Weights/blob/main/sdxl/pcm_sdxl_normalcfg_8step_converted.safetensors",
|
21 |
-
"https://huggingface.co/wangfuyun/PCM_Weights/blob/main/sdxl/pcm_sdxl_normalcfg_16step_converted.safetensors",
|
22 |
-
"https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-1step-lora.safetensors",
|
23 |
-
"https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-2steps-lora.safetensors",
|
24 |
-
"https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-4steps-lora.safetensors",
|
25 |
-
"https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-8steps-CFG-lora.safetensors",
|
26 |
-
"https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-12steps-CFG-lora.safetensors",
|
27 |
-
"https://huggingface.co/latent-consistency/lcm-lora-sdxl/blob/main/pytorch_lora_weights.safetensors",
|
28 |
-
]
|
29 |
-
schedulers = list(SCHEDULER_CONFIG_MAP.keys())
|
30 |
-
|
31 |
-
preset_dict = {
|
32 |
-
"Default": [True, "", "Euler a", "", 1.0, "", 1.0, "", 1.0, "", 1.0, "", 1.0],
|
33 |
-
"Bake in standard VAE": [True, "https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl.vae.safetensors",
|
34 |
-
"Euler a", "", 1.0, "", 1.0, "", 1.0, "", 1.0, "", 1.0],
|
35 |
-
"Hyper-SDXL / SPO": [True, "https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/blob/main/sdxl.vae.safetensors",
|
36 |
-
"TCD", "https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SDXL-8steps-CFG-lora.safetensors", 1.0,
|
37 |
-
"https://huggingface.co/SPO-Diffusion-Models/SPO-SDXL_4k-p_10ep_LoRA/blob/main/spo_sdxl_10ep_4k-data_lora_diffusers.safetensors",
|
38 |
-
1.0, "", 1.0, "", 1.0, "", 1.0],
|
39 |
-
}
|
40 |
-
|
41 |
-
|
42 |
-
def set_presets(preset: str="Default"):
|
43 |
-
p = []
|
44 |
-
if preset in preset_dict.keys(): p = preset_dict[preset]
|
45 |
-
else: p = preset_dict["Default"]
|
46 |
-
return p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12]
|
47 |
-
|
48 |
|
49 |
css = """"""
|
50 |
|
51 |
-
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
|
52 |
-
gr.Markdown("# Download and convert any Stable Diffusion XL safetensors to Diffusers and create your repo")
|
53 |
gr.Markdown(
|
54 |
-
|
55 |
-
- [A CLI version of this tool
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
- Patiently wait until the output changes. It takes approximately 2 to 3 minutes (downloading from HF).
|
72 |
-
"""
|
73 |
-
)
|
74 |
-
with gr.Column():
|
75 |
-
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)
|
76 |
-
hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value="", max_lines=1)
|
77 |
-
hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value="", max_lines=1)
|
78 |
-
hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
|
79 |
-
civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
|
80 |
-
is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
|
81 |
-
is_private = gr.Checkbox(label="Create private repo", value=True, visible=False)
|
82 |
-
presets = gr.Radio(label="Presets", choices=list(preset_dict.keys()), value="Default")
|
83 |
-
with gr.Accordion("Advanced settings", open=False):
|
84 |
-
is_half = gr.Checkbox(label="Half precision", value=True)
|
85 |
-
vae = gr.Dropdown(label="VAE", choices=vaes, value="", allow_custom_value=True)
|
86 |
-
scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
|
87 |
-
lora1 = gr.Dropdown(label="LoRA1", choices=loras, value="", allow_custom_value=True)
|
88 |
-
lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
|
89 |
-
lora2 = gr.Dropdown(label="LoRA2", choices=loras, value="", allow_custom_value=True)
|
90 |
-
lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
|
91 |
-
lora3 = gr.Dropdown(label="LoRA3", choices=loras, value="", allow_custom_value=True)
|
92 |
-
lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
|
93 |
-
lora4 = gr.Dropdown(label="LoRA4", choices=loras, value="", allow_custom_value=True)
|
94 |
-
lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
|
95 |
-
lora5 = gr.Dropdown(label="LoRA5", choices=loras, value="", allow_custom_value=True)
|
96 |
-
lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
|
97 |
-
run_button = gr.Button(value="Submit")
|
98 |
-
repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
|
99 |
-
output_md = gr.Markdown(label="Output")
|
100 |
-
gr.DuplicateButton(value="Duplicate Space")
|
101 |
|
102 |
gr.on(
|
103 |
-
triggers=[run_button.click],
|
104 |
-
fn=
|
105 |
-
inputs=[
|
106 |
-
|
107 |
-
outputs=[repo_urls, output_md],
|
108 |
-
)
|
109 |
-
presets.change(
|
110 |
-
fn=set_presets,
|
111 |
-
inputs=[presets],
|
112 |
-
outputs=[is_half, vae, scheduler, lora1, lora1s, lora2, lora2s, lora3, lora3s, lora4, lora4s, lora5, lora5s],
|
113 |
-
queue=False,
|
114 |
)
|
115 |
|
116 |
demo.queue()
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
from convert_repo_to_safetensors_gr import convert_repo_to_safetensors_multi
|
4 |
+
os.environ['HF_OUTPUT_REPO'] = 'John6666/safetensors_converting_test'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
css = """"""
|
7 |
|
8 |
+
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
|
|
|
9 |
gr.Markdown(
|
10 |
+
f"""
|
11 |
+
- [A CLI version of this tool is available here](https://huggingface.co/spaces/John6666/convert_repo_to_safetensors/tree/main/local).
|
12 |
+
""")
|
13 |
+
with gr.Column():
|
14 |
+
repo_id = gr.Textbox(label="Repo ID", placeholder="author/model", value="", lines=1)
|
15 |
+
is_upload = gr.Checkbox(label="Upload safetensors to HF Repo", info="Fast download, but files will be public.", value=False)
|
16 |
+
with gr.Accordion("Advanced", open=False):
|
17 |
+
dtype = gr.Radio(label="Output data type", choices=["fp16", "fp32", "bf16", "default"], value="fp16")
|
18 |
+
hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
|
19 |
+
with gr.Row():
|
20 |
+
newrepo_id = gr.Textbox(label="Upload repo ID", placeholder="author/model", value="", max_lines=1)
|
21 |
+
newrepo_type = gr.Radio(label="Upload repo type", choices=["model", "dataset"], value="model")
|
22 |
+
is_private = gr.Checkbox(label="Create / Use private repo", value=True)
|
23 |
+
uploaded_urls = gr.CheckboxGroup(visible=False, choices=[], value=None) # hidden
|
24 |
+
run_button = gr.Button(value="Convert")
|
25 |
+
st_file = gr.Files(label="Output", interactive=False)
|
26 |
+
st_md = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
gr.on(
|
29 |
+
triggers=[repo_id.submit, run_button.click],
|
30 |
+
fn=convert_repo_to_safetensors_multi,
|
31 |
+
inputs=[repo_id, hf_token, st_file, uploaded_urls, dtype, is_upload, newrepo_id, newrepo_type, is_private],
|
32 |
+
outputs=[st_file, uploaded_urls, st_md],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
demo.queue()
|
convert_repo_to_safetensors_gr.py
CHANGED
@@ -374,6 +374,7 @@ def upload_safetensors_to_repo(filename, repo_id, repo_type, is_private, progres
|
|
374 |
url = hf_hub_url(repo_id=repo_id, repo_type=repo_type, filename=output_filename, token=get_token())
|
375 |
except Exception as e:
|
376 |
print(f"Error: Failed to upload to {repo_id}. {e}")
|
|
|
377 |
return None
|
378 |
return url
|
379 |
|
@@ -381,8 +382,8 @@ def upload_safetensors_to_repo(filename, repo_id, repo_type, is_private, progres
|
|
381 |
def convert_repo_to_safetensors(repo_id, dtype="fp16", progress=gr.Progress(track_tqdm=True)):
|
382 |
download_dir = f"{repo_id.split('/')[0]}_{repo_id.split('/')[-1]}"
|
383 |
output_filename = f"{repo_id.split('/')[0]}_{repo_id.split('/')[-1]}.safetensors"
|
384 |
-
download_repo(repo_id, download_dir)
|
385 |
-
convert_diffusers_to_safetensors(download_dir, output_filename, dtype)
|
386 |
return output_filename
|
387 |
|
388 |
|
|
|
374 |
url = hf_hub_url(repo_id=repo_id, repo_type=repo_type, filename=output_filename, token=get_token())
|
375 |
except Exception as e:
|
376 |
print(f"Error: Failed to upload to {repo_id}. {e}")
|
377 |
+
gr.Warning(print(f"Error: Failed to upload to {repo_id}. {e}"))
|
378 |
return None
|
379 |
return url
|
380 |
|
|
|
382 |
def convert_repo_to_safetensors(repo_id, dtype="fp16", progress=gr.Progress(track_tqdm=True)):
|
383 |
download_dir = f"{repo_id.split('/')[0]}_{repo_id.split('/')[-1]}"
|
384 |
output_filename = f"{repo_id.split('/')[0]}_{repo_id.split('/')[-1]}.safetensors"
|
385 |
+
download_repo(repo_id, download_dir, progress)
|
386 |
+
convert_diffusers_to_safetensors(download_dir, output_filename, dtype, progress)
|
387 |
return output_filename
|
388 |
|
389 |
|