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)
import os
HF_USER = os.getenv("HF_USER", "")
HF_REPO = os.getenv("HF_REPO", "")
HF_URL = os.getenv("HF_URL", "")
HF_OW = os.getenv("HF_OW", False)
HF_PR = os.getenv("HF_PR", False)
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="theNeofr/Syne", 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"""
### ⚠️AVISO IMPORTANTE⚠️
Es peligroso exponer su token o clave de acceso a otros.
Si lo utiliza, le recomiendo que duplique este espacio en su propia cuenta HF con antelación.
Las claves y tokens se pueden configurar en **Secreto** (`HF_TOKEN`, `CIVITAI_API_KEY`) si está colocado en tu propio espacio.
Le ahorra la molestia de escribirlos.
Apenas funciona en el espacio de la CPU, pero se pueden convertir archivos más grandes si se duplican en el espacio más potente **Zero GPU**.
En particular, la conversión de FLUX.1 o SD 3.5 es casi imposible en el espacio de la CPU.
### Los pasos son los siguientes:
1. Pegue un token de acceso en write desde [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
1. Ingrese una URL de descarga del modelo de Hugging Face o Civitai u otros sitios.
1. Si desea descargar un modelo de Civitai, pegue una clave API de Civitai.
1. Ingrese su ID de usuario de HF. por ejemplo, 'tuid'.
1. Ingrese su nuevo nombre de repositorio. Si está vacío, autocompletar. por ejemplo, 'newrepo'.
1. Configure los parámetros. Si no está seguro, utilice los valores predeterminados.
1. Haga clic en "Enviar".
1. Espere pacientemente hasta que cambie la salida. La descarga desde HF tarda aproximadamente de 2 a 3 minutos (en los modelos SDXL).).
""")
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=HF_URL, max_lines=1)
with gr.Group():
with gr.Row():
hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value=HF_USER, max_lines=1)
hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value=HF_REPO, 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)
gated = gr.Radio(label="Create gated repo", info="Gated repo must be public", choices=["auto", "manual", "False"], value="False")
with gr.Row():
is_overwrite = gr.Checkbox(label="Overwrite repo", value=HF_OW)
is_pr = gr.Checkbox(label="Create PR", value=HF_PR)
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)
sdxl_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
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_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
sdxl_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
with gr.Column():
with gr.Row():
sdxl_lora1 = gr.Dropdown(label="LoRA1", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sdxl_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Row():
sdxl_lora2 = gr.Dropdown(label="LoRA2", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sdxl_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Row():
sdxl_lora3 = gr.Dropdown(label="LoRA3", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sdxl_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Row():
sdxl_lora4 = gr.Dropdown(label="LoRA4", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sdxl_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Row():
sdxl_lora5 = gr.Dropdown(label="LoRA5", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
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)
sd15_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
with gr.Row():
sd15_ema = gr.Checkbox(label="Extract EMA", value=True, visible=True)
sd15_isize = gr.Radio(label="Image size", choices=["768", "512"], value="768")
sd15_sc = gr.Checkbox(label="Safety checker", value=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_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler")
sd15_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
with gr.Column():
with gr.Row():
sd15_lora1 = gr.Dropdown(label="LoRA1", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd15_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Row():
sd15_lora2 = gr.Dropdown(label="LoRA2", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd15_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Row():
sd15_lora3 = gr.Dropdown(label="LoRA3", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd15_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Row():
sd15_lora4 = gr.Dropdown(label="LoRA4", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd15_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Row():
sd15_lora5 = gr.Dropdown(label="LoRA5", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
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)
flux_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
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_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
with gr.Row():
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)
with gr.Column():
with gr.Row():
flux_lora1 = gr.Dropdown(label="LoRA1", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
flux_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Row():
flux_lora2 = gr.Dropdown(label="LoRA2", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
flux_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Row():
flux_lora3 = gr.Dropdown(label="LoRA3", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
flux_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Row():
flux_lora4 = gr.Dropdown(label="LoRA4", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
flux_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Row():
flux_lora5 = gr.Dropdown(label="LoRA5", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
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)
sd35_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
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_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
with gr.Row():
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)
with gr.Column():
with gr.Row():
sd35_lora1 = gr.Dropdown(label="LoRA1", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd35_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
with gr.Row():
sd35_lora2 = gr.Dropdown(label="LoRA2", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd35_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
with gr.Row():
sd35_lora3 = gr.Dropdown(label="LoRA3", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd35_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
with gr.Row():
sd35_lora4 = gr.Dropdown(label="LoRA4", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
sd35_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
with gr.Row():
sd35_lora5 = gr.Dropdown(label="LoRA5", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
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")
adv_args = gr.Textbox(label="Advanced arguments", value="", visible=False)
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.Markdown("This webui was redesigned with ❤ by [theNeofr](https://huggingface.co/theNeofr)")
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, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
sdxl_dtype, sdxl_vae, sdxl_clip, flux_t5, sdxl_scheduler, sd15_ema, sd15_isize, sd15_sc, flux_base_repo, sdxl_mtype,
sdxl_lora1, sdxl_lora1s, sdxl_lora2, sdxl_lora2s, sdxl_lora3, sdxl_lora3s, sdxl_lora4, sdxl_lora4s, sdxl_lora5, sdxl_lora5s, adv_args],
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, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
sd15_dtype, sd15_vae, sd15_clip, flux_t5, sd15_scheduler, sd15_ema, sd15_isize, sd15_sc, flux_base_repo, sd15_mtype,
sd15_lora1, sd15_lora1s, sd15_lora2, sd15_lora2s, sd15_lora3, sd15_lora3s, sd15_lora4, sd15_lora4s, sd15_lora5, sd15_lora5s, adv_args],
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, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
flux_dtype, flux_vae, flux_clip, flux_t5, flux_scheduler, sd15_ema, sd15_isize, sd15_sc, 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, adv_args],
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, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
sd35_dtype, sd35_vae, sd35_clip, sd35_t5, sd35_scheduler, sd15_ema, sd15_isize, sd15_sc, 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, adv_args],
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(ssr_mode=False)