import gradio as gr import os from convert_repo_to_safetensors_sd_gr import convert_repo_to_safetensors_multi_sd, clear_safetensors os.environ['HF_OUTPUT_REPO'] = 'John6666/safetensors_converting_test' css = """""" with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo: gr.Markdown( f""" - [A CLI version of this tool is available here](https://huggingface.co/spaces/John6666/convert_repo_to_safetensors_sd/tree/main/local). """) 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", "default"], value="fp16") 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 / Use private repo", value=True) uploaded_urls = gr.CheckboxGroup(visible=False, choices=[], value=None) # hidden 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.on( triggers=[repo_id.submit, run_button.click], fn=convert_repo_to_safetensors_multi_sd, 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()