import gradio as gr
from convert_url_to_diffusers_multi_gr import convert_url_to_diffusers_repo, get_dtypes, FLUX_BASE_REPOS, SD35_BASE_REPOS
from presets import (DEFAULT_DTYPE, schedulers, clips, t5s, sdxl_vaes, sdxl_loras, sdxl_preset_dict, sdxl_set_presets,
sd15_vaes, sd15_loras, sd15_preset_dict, sd15_set_presets, flux_vaes, flux_loras, flux_preset_dict, flux_set_presets,
sd35_vaes, sd35_loras, sd35_preset_dict, sd35_set_presets)
css = """
.title { font-size: 3em; align-items: center; text-align: center; }
.info { align-items: center; text-align: center; }
.block.result { margin: 1em 0; padding: 1em; box-shadow: 0 0 3px 3px #664422, 0 0 3px 2px #664422 inset; border-radius: 6px; background: #665544; }
"""
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
gr.Markdown("# Download SDXL / SD 1.5 / SD 3.5 / FLUX.1 safetensors and convert to HF🤗 Diffusers format and create your repo", elem_classes="title")
gr.Markdown(f"""
### ⚠️IMPORTANT NOTICE⚠️
It's dangerous to expose your access token or key to others.
If you do use it, I recommend that you duplicate this space on your own HF account in advance.
Keys and tokens could be set to **Secrets** (`HF_TOKEN`, `CIVITAI_API_KEY`) if it's placed in your own space.
It saves you the trouble of typing them in.
It barely works in the CPU space, but larger files can be converted if duplicated on the more powerful **Zero GPU** space.
In particular, conversion of FLUX.1 or SD 3.5 is almost impossible in CPU space.
### The steps are the following:
1. Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co./settings/tokens).
1. Input a model download url of the Hugging Face or Civitai or other sites.
1. If you want to download a model from Civitai, paste a Civitai API Key.
1. Input your HF user ID. e.g. 'yourid'.
1. Input your new repo name. If empty, auto-complete. e.g. 'newrepo'.
1. Set the parameters. If not sure, just use the defaults.
1. Click "Submit".
1. Patiently wait until the output changes. It takes approximately 2 to 3 minutes (on SDXL models downloading from HF).
""")
with gr.Column():
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)
with gr.Group():
with gr.Row():
hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value="", max_lines=1)
hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value="", max_lines=1)
with gr.Row(equal_height=True):
with gr.Column():
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).", elem_classes="info")
with gr.Column():
civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
gr.Markdown("Your Civitai API key is available at [https://civitai.com/user/account](https://civitai.com/user/account).", elem_classes="info")
with gr.Row():
is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
is_private = gr.Checkbox(label="Create private repo", value=True)
is_overwrite = gr.Checkbox(label="Overwrite repo", value=False)
with gr.Tab("SDXL"):
with gr.Group():
sdxl_presets = gr.Radio(label="Presets", choices=list(sdxl_preset_dict.keys()), value=list(sdxl_preset_dict.keys())[0])
sdxl_mtype = gr.Textbox(value="SDXL", visible=False)
with gr.Row():
sdxl_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
sdxl_ema = gr.Checkbox(label="Extract EMA", info="For SD 1.5", value=True, visible=False)
sdxl_base_repo = gr.Dropdown(label="Base repo ID", choices=FLUX_BASE_REPOS, value=FLUX_BASE_REPOS[0], allow_custom_value=True, visible=False)
with gr.Accordion("Advanced settings", open=False):
with gr.Row():
sdxl_vae = gr.Dropdown(label="VAE", choices=sdxl_vaes, value="", allow_custom_value=True)
sdxl_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
sdxl_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True, visible=False)
sdxl_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
with gr.Row():
with gr.Column():
sdxl_lora1 = gr.Dropdown(label="LoRA1", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320)
sdxl_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Column():
sdxl_lora2 = gr.Dropdown(label="LoRA2", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320)
sdxl_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Column():
sdxl_lora3 = gr.Dropdown(label="LoRA3", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320)
sdxl_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Column():
sdxl_lora4 = gr.Dropdown(label="LoRA4", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320)
sdxl_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Column():
sdxl_lora5 = gr.Dropdown(label="LoRA5", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320)
sdxl_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
sdxl_run_button = gr.Button(value="Submit", variant="primary")
with gr.Tab("SD 1.5"):
with gr.Group():
sd15_presets = gr.Radio(label="Presets", choices=list(sd15_preset_dict.keys()), value=list(sd15_preset_dict.keys())[0])
sd15_mtype = gr.Textbox(value="SD 1.5", visible=False)
with gr.Row():
sd15_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
sd15_ema = gr.Checkbox(label="Extract EMA", info="For SD 1.5", value=True, visible=True)
sd15_base_repo = gr.Dropdown(label="Base repo ID", choices=FLUX_BASE_REPOS, value=FLUX_BASE_REPOS[0], allow_custom_value=True, visible=False)
with gr.Accordion("Advanced settings", open=False):
with gr.Row():
sd15_vae = gr.Dropdown(label="VAE", choices=sd15_vaes, value="", allow_custom_value=True)
sd15_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
sd15_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True, visible=False)
sd15_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler")
with gr.Row():
with gr.Column():
sd15_lora1 = gr.Dropdown(label="LoRA1", choices=sd15_loras, value="", allow_custom_value=True, min_width=320)
sd15_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Column():
sd15_lora2 = gr.Dropdown(label="LoRA2", choices=sd15_loras, value="", allow_custom_value=True, min_width=320)
sd15_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Column():
sd15_lora3 = gr.Dropdown(label="LoRA3", choices=sd15_loras, value="", allow_custom_value=True, min_width=320)
sd15_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Column():
sd15_lora4 = gr.Dropdown(label="LoRA4", choices=sd15_loras, value="", allow_custom_value=True, min_width=320)
sd15_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Column():
sd15_lora5 = gr.Dropdown(label="LoRA5", choices=sd15_loras, value="", allow_custom_value=True, min_width=320)
sd15_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
sd15_run_button = gr.Button(value="Submit", variant="primary")
with gr.Tab("FLUX.1"):
with gr.Group():
flux_presets = gr.Radio(label="Presets", choices=list(flux_preset_dict.keys()), value=list(flux_preset_dict.keys())[0])
flux_mtype = gr.Textbox(value="FLUX", visible=False)
with gr.Row():
flux_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
flux_ema = gr.Checkbox(label="Extract EMA", info="For SD 1.5", value=True, visible=False)
flux_base_repo = gr.Dropdown(label="Base repo ID", choices=FLUX_BASE_REPOS, value=FLUX_BASE_REPOS[0], allow_custom_value=True, visible=True)
with gr.Accordion("Advanced settings", open=False):
with gr.Row():
flux_vae = gr.Dropdown(label="VAE", choices=flux_vaes, value="", allow_custom_value=True)
flux_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
flux_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True)
flux_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
with gr.Row():
with gr.Column():
flux_lora1 = gr.Dropdown(label="LoRA1", choices=flux_loras, value="", allow_custom_value=True, min_width=320)
flux_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Column():
flux_lora2 = gr.Dropdown(label="LoRA2", choices=flux_loras, value="", allow_custom_value=True, min_width=320)
flux_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Column():
flux_lora3 = gr.Dropdown(label="LoRA3", choices=flux_loras, value="", allow_custom_value=True, min_width=320)
flux_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Column():
flux_lora4 = gr.Dropdown(label="LoRA4", choices=flux_loras, value="", allow_custom_value=True, min_width=320)
flux_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Column():
flux_lora5 = gr.Dropdown(label="LoRA5", choices=flux_loras, value="", allow_custom_value=True, min_width=320)
flux_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
flux_run_button = gr.Button(value="Submit", variant="primary")
with gr.Tab("SD 3.5"):
with gr.Group():
sd35_presets = gr.Radio(label="Presets", choices=list(sd35_preset_dict.keys()), value=list(sd35_preset_dict.keys())[0])
sd35_mtype = gr.Textbox(value="SD 3.5", visible=False)
with gr.Row():
sd35_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
sd35_ema = gr.Checkbox(label="Extract EMA", info="For SD 1.5", value=True, visible=False)
sd35_base_repo = gr.Dropdown(label="Base repo ID", choices=SD35_BASE_REPOS, value=SD35_BASE_REPOS[0], allow_custom_value=True, visible=True)
with gr.Accordion("Advanced settings", open=False):
with gr.Row():
sd35_vae = gr.Dropdown(label="VAE", choices=sd35_vaes, value="", allow_custom_value=True)
sd35_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
sd35_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True)
sd35_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
with gr.Row():
with gr.Column():
sd35_lora1 = gr.Dropdown(label="LoRA1", choices=sd35_loras, value="", allow_custom_value=True, min_width=320)
sd35_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Column():
sd35_lora2 = gr.Dropdown(label="LoRA2", choices=sd35_loras, value="", allow_custom_value=True, min_width=320)
sd35_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Column():
sd35_lora3 = gr.Dropdown(label="LoRA3", choices=sd35_loras, value="", allow_custom_value=True, min_width=320)
sd35_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Column():
sd35_lora4 = gr.Dropdown(label="LoRA4", choices=sd35_loras, value="", allow_custom_value=True, min_width=320)
sd35_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Column():
sd35_lora5 = gr.Dropdown(label="LoRA5", choices=sd35_loras, value="", allow_custom_value=True, min_width=320)
sd35_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
sd35_run_button = gr.Button(value="Submit", variant="primary")
with gr.Group():
repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=[])
output_md = gr.Markdown(label="Output", value="
", elem_classes="result")
clear_button = gr.Button(value="Clear Output", variant="secondary")
gr.DuplicateButton(value="Duplicate Space")
gr.on(
triggers=[sdxl_run_button.click],
fn=convert_url_to_diffusers_repo,
inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, is_overwrite, is_upload_sf, repo_urls,
sdxl_dtype, sdxl_vae, sdxl_clip, sdxl_t5, sdxl_scheduler, sdxl_ema, sdxl_base_repo, sdxl_mtype,
sdxl_lora1, sdxl_lora1s, sdxl_lora2, sdxl_lora2s, sdxl_lora3, sdxl_lora3s, sdxl_lora4, sdxl_lora4s, sdxl_lora5, sdxl_lora5s],
outputs=[repo_urls, output_md],
)
sdxl_presets.change(
fn=sdxl_set_presets,
inputs=[sdxl_presets],
outputs=[sdxl_dtype, sdxl_vae, sdxl_scheduler, sdxl_lora1, sdxl_lora1s, sdxl_lora2, sdxl_lora2s, sdxl_lora3, sdxl_lora3s,
sdxl_lora4, sdxl_lora4s, sdxl_lora5, sdxl_lora5s],
queue=False,
)
gr.on(
triggers=[sd15_run_button.click],
fn=convert_url_to_diffusers_repo,
inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, is_overwrite, is_upload_sf, repo_urls,
sd15_dtype, sd15_vae, sd15_clip, sd15_t5, sd15_scheduler, sd15_ema, sd15_base_repo, sd15_mtype,
sd15_lora1, sd15_lora1s, sd15_lora2, sd15_lora2s, sd15_lora3, sd15_lora3s, sd15_lora4, sd15_lora4s, sd15_lora5, sd15_lora5s],
outputs=[repo_urls, output_md],
)
sd15_presets.change(
fn=sd15_set_presets,
inputs=[sd15_presets],
outputs=[sd15_dtype, sd15_vae, sd15_scheduler, sd15_lora1, sd15_lora1s, sd15_lora2, sd15_lora2s, sd15_lora3, sd15_lora3s,
sd15_lora4, sd15_lora4s, sd15_lora5, sd15_lora5s, sd15_ema],
queue=False,
)
gr.on(
triggers=[flux_run_button.click],
fn=convert_url_to_diffusers_repo,
inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, is_overwrite, is_upload_sf, repo_urls,
flux_dtype, flux_vae, flux_clip, flux_t5, flux_scheduler, flux_ema, flux_base_repo, flux_mtype,
flux_lora1, flux_lora1s, flux_lora2, flux_lora2s, flux_lora3, flux_lora3s, flux_lora4, flux_lora4s, flux_lora5, flux_lora5s],
outputs=[repo_urls, output_md],
)
flux_presets.change(
fn=flux_set_presets,
inputs=[flux_presets],
outputs=[flux_dtype, flux_vae, flux_scheduler, flux_lora1, flux_lora1s, flux_lora2, flux_lora2s, flux_lora3, flux_lora3s,
flux_lora4, flux_lora4s, flux_lora5, flux_lora5s, flux_base_repo],
queue=False,
)
gr.on(
triggers=[sd35_run_button.click],
fn=convert_url_to_diffusers_repo,
inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, is_overwrite, is_upload_sf, repo_urls,
sd35_dtype, sd35_vae, sd35_clip, sd35_t5, sd35_scheduler, sd35_ema, sd35_base_repo, sd35_mtype,
sd35_lora1, sd35_lora1s, sd35_lora2, sd35_lora2s, sd35_lora3, sd35_lora3s, sd35_lora4, sd35_lora4s, sd35_lora5, sd35_lora5s],
outputs=[repo_urls, output_md],
)
sd35_presets.change(
fn=sd35_set_presets,
inputs=[sd35_presets],
outputs=[sd35_dtype, sd35_vae, sd35_scheduler, sd35_lora1, sd35_lora1s, sd35_lora2, sd35_lora2s, sd35_lora3, sd35_lora3s,
sd35_lora4, sd35_lora4s, sd35_lora5, sd35_lora5s, sd35_base_repo],
queue=False,
)
clear_button.click(lambda: ([], "
"), None, [repo_urls, output_md], queue=False, show_api=False)
demo.queue()
demo.launch()