import gradio as gr from civitai_to_hf import search_civitai, download_civitai, select_civitai_item, CIVITAI_TYPE, CIVITAI_BASEMODEL, CIVITAI_SORT, CIVITAI_PERIOD css = """ .title { text-align: center; !important; } """ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo: with gr.Column(): gr.Markdown("# Civitai to HF Downloader Alpha", elem_classes="title") with gr.Accordion("Search Civitai", open=False): with gr.Row(): search_civitai_type = gr.CheckboxGroup(label="Type", choices=CIVITAI_TYPE, value=[]) search_civitai_basemodel = gr.CheckboxGroup(label="Base model", choices=CIVITAI_BASEMODEL, value=[]) with gr.Row(): search_civitai_sort = gr.Radio(label="Sort", choices=CIVITAI_SORT, value=CIVITAI_SORT[0]) search_civitai_period = gr.Radio(label="Period", choices=CIVITAI_PERIOD, value="Month") with gr.Row(): search_civitai_query = gr.Textbox(label="Query", placeholder="flux", lines=1) search_civitai_tag = gr.Textbox(label="Tag", lines=1) search_civitai_submit = gr.Button("Search on Civitai") with gr.Row(): search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False) search_civitai_json = gr.JSON(value={}, visible=False) search_civitai_desc = gr.Markdown(value="", visible=False) dl_url = gr.Textbox(label="Download URL", placeholder="https://civitai.com/api/download/models/28907", value="", lines=1) civitai_key = gr.Textbox(label="Your Civitai Key", value="", max_lines=1) 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/yourrepo", 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) # hidden run_button = gr.Button(value="Download and Upload") urls_md = gr.Markdown() gr.DuplicateButton(value="Duplicate Space") gr.on( triggers=[run_button.click], fn=download_civitai, inputs=[dl_url, civitai_key, hf_token, uploaded_urls, newrepo_id, newrepo_type, is_private], outputs=[uploaded_urls, urls_md], ) gr.on( triggers=[search_civitai_submit.click, search_civitai_query.submit, search_civitai_tag.submit], fn=search_civitai, inputs=[search_civitai_query, search_civitai_type, search_civitai_basemodel, search_civitai_sort, search_civitai_period, search_civitai_tag], outputs=[search_civitai_result, search_civitai_desc, search_civitai_submit, search_civitai_query], queue=True, show_api=False, ) search_civitai_result.change(select_civitai_item, [search_civitai_result], [dl_url, search_civitai_desc], queue=False, show_api=False) demo.queue() demo.launch()