Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,80 +1,80 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from civitai_to_hf import (search_civitai, download_civitai, select_civitai_item, add_civitai_item, get_civitai_tag, select_civitai_all_item,
|
3 |
-
CIVITAI_TYPE, CIVITAI_BASEMODEL, CIVITAI_SORT, CIVITAI_PERIOD)
|
4 |
-
|
5 |
-
css = """
|
6 |
-
.title { font-size: 3em; align-items: center; text-align: center; }
|
7 |
-
.info { align-items: center; text-align: center; }
|
8 |
-
.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; }
|
9 |
-
.desc [src$='#float'] { float: right; margin: 20px; }
|
10 |
-
"""
|
11 |
-
|
12 |
-
with gr.Blocks(theme="
|
13 |
-
with gr.Column():
|
14 |
-
gr.Markdown("# CivitAI to HF🤗 Downloader & Uploader", elem_classes="title")
|
15 |
-
with gr.Accordion("Search Civitai", open=True):
|
16 |
-
with gr.Row():
|
17 |
-
search_civitai_type = gr.CheckboxGroup(label="Type", choices=CIVITAI_TYPE, value=["Checkpoint", "LORA"])
|
18 |
-
search_civitai_basemodel = gr.CheckboxGroup(label="Base model", choices=CIVITAI_BASEMODEL, value=[])
|
19 |
-
with gr.Row():
|
20 |
-
search_civitai_sort = gr.Radio(label="Sort", choices=CIVITAI_SORT, value=CIVITAI_SORT[0])
|
21 |
-
search_civitai_period = gr.Radio(label="Period", choices=CIVITAI_PERIOD, value="Month")
|
22 |
-
search_civitai_limit = gr.Slider(label="Limit", minimum=1, maximum=100, step=1, value=100)
|
23 |
-
search_civitai_page = gr.Slider(label="Page", minimum=1, maximum=100, step=1, value=1)
|
24 |
-
with gr.Row():
|
25 |
-
search_civitai_query = gr.Textbox(label="Query", placeholder="flux", lines=1)
|
26 |
-
search_civitai_tag = gr.Dropdown(label="Tag", choices=get_civitai_tag(), value=get_civitai_tag()[0], allow_custom_value=True)
|
27 |
-
search_civitai_user = gr.Textbox(label="Username", lines=1)
|
28 |
-
search_civitai_submit = gr.Button("Search on Civitai")
|
29 |
-
with gr.Accordion("Results", open=True):
|
30 |
-
with gr.Row():
|
31 |
-
search_civitai_desc = gr.Markdown(value="", visible=False, elem_classes="desc")
|
32 |
-
search_civitai_json = gr.JSON(value={}, visible=False)
|
33 |
-
with gr.Row():
|
34 |
-
with gr.Column(scale=9):
|
35 |
-
search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value=[],
|
36 |
-
allow_custom_value=True, visible=True, multiselect=True)
|
37 |
-
with gr.Column(scale=1):
|
38 |
-
search_civitai_add = gr.Button("Add to download URLs")
|
39 |
-
search_civitai_select_all = gr.Button("Select All", variant="secondary", size="sm")
|
40 |
-
with gr.Group():
|
41 |
-
dl_url = gr.Textbox(label="Download URL(s)", placeholder="https://civitai.com/api/download/models/28907\n...", value="", lines=3, max_lines=255)
|
42 |
-
with gr.Column():
|
43 |
-
civitai_key = gr.Textbox(label="Your Civitai Key", value="", max_lines=1)
|
44 |
-
gr.Markdown("Your Civitai API key is available at [https://civitai.com/user/account](https://civitai.com/user/account).", elem_classes="info")
|
45 |
-
with gr.Group():
|
46 |
-
with gr.Row():
|
47 |
-
with gr.Column():
|
48 |
-
hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
|
49 |
-
gr.Markdown("Your token is available at [hf.co/settings/tokens](https://huggingface.co/settings/tokens).", elem_classes="info")
|
50 |
-
newrepo_id = gr.Textbox(label="Upload repo ID", placeholder="yourid/yourrepo", value="", max_lines=1)
|
51 |
-
with gr.Row():
|
52 |
-
newrepo_type = gr.Radio(label="Upload repo type", choices=["model", "dataset"], value="model")
|
53 |
-
is_private = gr.Checkbox(label="Create private repo", value=True)
|
54 |
-
is_info = gr.Checkbox(label="Upload Civitai information files", value=False)
|
55 |
-
run_button = gr.Button(value="Download and Upload", variant="primary")
|
56 |
-
uploaded_urls = gr.CheckboxGroup(visible=False, choices=[], value=None) # hidden
|
57 |
-
urls_md = gr.Markdown("<br><br>", elem_classes="result")
|
58 |
-
gr.DuplicateButton(value="Duplicate Space")
|
59 |
-
|
60 |
-
gr.on(
|
61 |
-
triggers=[run_button.click],
|
62 |
-
fn=download_civitai,
|
63 |
-
inputs=[dl_url, civitai_key, hf_token, uploaded_urls, newrepo_id, newrepo_type, is_private, is_info],
|
64 |
-
outputs=[uploaded_urls, urls_md],
|
65 |
-
)
|
66 |
-
gr.on(
|
67 |
-
triggers=[search_civitai_submit.click, search_civitai_query.submit, search_civitai_user.submit],
|
68 |
-
fn=search_civitai,
|
69 |
-
inputs=[search_civitai_query, search_civitai_type, search_civitai_basemodel, search_civitai_sort,
|
70 |
-
search_civitai_period, search_civitai_tag, search_civitai_user, search_civitai_limit, search_civitai_page],
|
71 |
-
outputs=[search_civitai_result, search_civitai_desc, search_civitai_submit, search_civitai_query],
|
72 |
-
queue=True,
|
73 |
-
show_api=False,
|
74 |
-
)
|
75 |
-
search_civitai_result.change(select_civitai_item, [search_civitai_result], [search_civitai_desc, search_civitai_json], queue=False, show_api=False)
|
76 |
-
search_civitai_add.click(add_civitai_item, [search_civitai_result, dl_url], [dl_url], queue=False, show_api=False)
|
77 |
-
search_civitai_select_all.click(select_civitai_all_item, [search_civitai_select_all], [search_civitai_select_all, search_civitai_result], queue=False, show_api=False)
|
78 |
-
|
79 |
-
demo.queue()
|
80 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from civitai_to_hf import (search_civitai, download_civitai, select_civitai_item, add_civitai_item, get_civitai_tag, select_civitai_all_item,
|
3 |
+
CIVITAI_TYPE, CIVITAI_BASEMODEL, CIVITAI_SORT, CIVITAI_PERIOD)
|
4 |
+
|
5 |
+
css = """
|
6 |
+
.title { font-size: 3em; align-items: center; text-align: center; }
|
7 |
+
.info { align-items: center; text-align: center; }
|
8 |
+
.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; }
|
9 |
+
.desc [src$='#float'] { float: right; margin: 20px; }
|
10 |
+
"""
|
11 |
+
|
12 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
|
13 |
+
with gr.Column():
|
14 |
+
gr.Markdown("# CivitAI to HF🤗 Downloader & Uploader", elem_classes="title")
|
15 |
+
with gr.Accordion("Search Civitai", open=True):
|
16 |
+
with gr.Row():
|
17 |
+
search_civitai_type = gr.CheckboxGroup(label="Type", choices=CIVITAI_TYPE, value=["Checkpoint", "LORA"])
|
18 |
+
search_civitai_basemodel = gr.CheckboxGroup(label="Base model", choices=CIVITAI_BASEMODEL, value=[])
|
19 |
+
with gr.Row():
|
20 |
+
search_civitai_sort = gr.Radio(label="Sort", choices=CIVITAI_SORT, value=CIVITAI_SORT[0])
|
21 |
+
search_civitai_period = gr.Radio(label="Period", choices=CIVITAI_PERIOD, value="Month")
|
22 |
+
search_civitai_limit = gr.Slider(label="Limit", minimum=1, maximum=100, step=1, value=100)
|
23 |
+
search_civitai_page = gr.Slider(label="Page", minimum=1, maximum=100, step=1, value=1)
|
24 |
+
with gr.Row():
|
25 |
+
search_civitai_query = gr.Textbox(label="Query", placeholder="flux", lines=1)
|
26 |
+
search_civitai_tag = gr.Dropdown(label="Tag", choices=get_civitai_tag(), value=get_civitai_tag()[0], allow_custom_value=True)
|
27 |
+
search_civitai_user = gr.Textbox(label="Username", lines=1)
|
28 |
+
search_civitai_submit = gr.Button("Search on Civitai")
|
29 |
+
with gr.Accordion("Results", open=True):
|
30 |
+
with gr.Row():
|
31 |
+
search_civitai_desc = gr.Markdown(value="", visible=False, elem_classes="desc")
|
32 |
+
search_civitai_json = gr.JSON(value={}, visible=False)
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column(scale=9):
|
35 |
+
search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value=[],
|
36 |
+
allow_custom_value=True, visible=True, multiselect=True)
|
37 |
+
with gr.Column(scale=1):
|
38 |
+
search_civitai_add = gr.Button("Add to download URLs")
|
39 |
+
search_civitai_select_all = gr.Button("Select All", variant="secondary", size="sm")
|
40 |
+
with gr.Group():
|
41 |
+
dl_url = gr.Textbox(label="Download URL(s)", placeholder="https://civitai.com/api/download/models/28907\n...", value="", lines=3, max_lines=255)
|
42 |
+
with gr.Column():
|
43 |
+
civitai_key = gr.Textbox(label="Your Civitai Key", value="", max_lines=1)
|
44 |
+
gr.Markdown("Your Civitai API key is available at [https://civitai.com/user/account](https://civitai.com/user/account).", elem_classes="info")
|
45 |
+
with gr.Group():
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
|
49 |
+
gr.Markdown("Your token is available at [hf.co/settings/tokens](https://huggingface.co/settings/tokens).", elem_classes="info")
|
50 |
+
newrepo_id = gr.Textbox(label="Upload repo ID", placeholder="yourid/yourrepo", value="", max_lines=1)
|
51 |
+
with gr.Row():
|
52 |
+
newrepo_type = gr.Radio(label="Upload repo type", choices=["model", "dataset"], value="model")
|
53 |
+
is_private = gr.Checkbox(label="Create private repo", value=True)
|
54 |
+
is_info = gr.Checkbox(label="Upload Civitai information files", value=False)
|
55 |
+
run_button = gr.Button(value="Download and Upload", variant="primary")
|
56 |
+
uploaded_urls = gr.CheckboxGroup(visible=False, choices=[], value=None) # hidden
|
57 |
+
urls_md = gr.Markdown("<br><br>", elem_classes="result")
|
58 |
+
gr.DuplicateButton(value="Duplicate Space")
|
59 |
+
|
60 |
+
gr.on(
|
61 |
+
triggers=[run_button.click],
|
62 |
+
fn=download_civitai,
|
63 |
+
inputs=[dl_url, civitai_key, hf_token, uploaded_urls, newrepo_id, newrepo_type, is_private, is_info],
|
64 |
+
outputs=[uploaded_urls, urls_md],
|
65 |
+
)
|
66 |
+
gr.on(
|
67 |
+
triggers=[search_civitai_submit.click, search_civitai_query.submit, search_civitai_user.submit],
|
68 |
+
fn=search_civitai,
|
69 |
+
inputs=[search_civitai_query, search_civitai_type, search_civitai_basemodel, search_civitai_sort,
|
70 |
+
search_civitai_period, search_civitai_tag, search_civitai_user, search_civitai_limit, search_civitai_page],
|
71 |
+
outputs=[search_civitai_result, search_civitai_desc, search_civitai_submit, search_civitai_query],
|
72 |
+
queue=True,
|
73 |
+
show_api=False,
|
74 |
+
)
|
75 |
+
search_civitai_result.change(select_civitai_item, [search_civitai_result], [search_civitai_desc, search_civitai_json], queue=False, show_api=False)
|
76 |
+
search_civitai_add.click(add_civitai_item, [search_civitai_result, dl_url], [dl_url], queue=False, show_api=False)
|
77 |
+
search_civitai_select_all.click(select_civitai_all_item, [search_civitai_select_all], [search_civitai_select_all, search_civitai_result], queue=False, show_api=False)
|
78 |
+
|
79 |
+
demo.queue()
|
80 |
+
demo.launch()
|