|
import gradio as gr
|
|
import os
|
|
from convert_repo_to_safetensors_gr import convert_repo_to_safetensors_multi, clear_safetensors
|
|
os.environ['HF_OUTPUT_REPO'] = 'John6666/safetensors_converting_test'
|
|
|
|
css = """
|
|
.title { text-align: center; !important; }
|
|
.footer { text-align: center; !important; }
|
|
"""
|
|
|
|
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
|
|
gr.Markdown("# HF Diffusers repo to WebUI/ComfyUI single safetensors file converter (for SDXL / SD 1.5 / LoRA)", elem_classes="title")
|
|
with gr.Column():
|
|
repo_id = gr.Textbox(label="Repo ID", placeholder="author/model", value="", lines=1)
|
|
is_upload = gr.Checkbox(label="Upload safetensors to HF Repo", info="Fast download, but files will be public.", value=False)
|
|
with gr.Accordion("Advanced", open=False):
|
|
dtype = gr.Radio(label="Output data type", choices=["fp16", "fp32", "bf16", "fp8", "default"], value="fp16")
|
|
with gr.Accordion("Upload to your repo", open=True):
|
|
with gr.Row():
|
|
hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
|
|
gr.Markdown("Your token is available at [hf.co/settings/tokens](https://huggingface.co/settings/tokens).")
|
|
with gr.Row():
|
|
newrepo_id = gr.Textbox(label="Upload repo ID", placeholder="yourid/newrepo", value="", max_lines=1)
|
|
newrepo_type = gr.Radio(label="Upload repo type", choices=["model", "dataset"], value="model")
|
|
is_private = gr.Checkbox(label="Create private repo", value=True)
|
|
uploaded_urls = gr.CheckboxGroup(visible=False, choices=[], value=None)
|
|
run_button = gr.Button(value="Convert")
|
|
st_file = gr.Files(label="Output", interactive=False)
|
|
st_md = gr.Markdown()
|
|
delete_button = gr.Button(value="Delete Safetensors")
|
|
gr.DuplicateButton(value="Duplicate Space")
|
|
gr.Markdown(
|
|
f"""
|
|
- Thanks to [xi0v](https://huggingface.co/xi0v)
|
|
- [A CLI version of this tool is available here](https://huggingface.co/spaces/John6666/convert_repo_to_safetensors/tree/main/local).
|
|
""", elem_classes="footer")
|
|
|
|
gr.on(
|
|
triggers=[repo_id.submit, run_button.click],
|
|
fn=convert_repo_to_safetensors_multi,
|
|
inputs=[repo_id, hf_token, st_file, uploaded_urls, dtype, is_upload, newrepo_id, newrepo_type, is_private],
|
|
outputs=[st_file, uploaded_urls, st_md],
|
|
)
|
|
delete_button.click(clear_safetensors, None, [st_file], queue=False, show_api=False)
|
|
|
|
demo.queue()
|
|
demo.launch()
|
|
|