Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from model import models
|
3 |
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
max_images = 8
|
9 |
MAX_SEED = 2**32-1
|
10 |
load_models(models)
|
@@ -15,21 +16,20 @@ css = """
|
|
15 |
.gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
|
16 |
"""
|
17 |
|
18 |
-
|
19 |
def set_token(token):
|
20 |
-
|
21 |
-
|
22 |
-
os.environ["HF_TOKEN"] = token # Сохраняем в переменной окружения
|
23 |
-
login(HF_TOKEN)
|
24 |
-
return "Токен установлен!"
|
25 |
|
26 |
-
|
27 |
-
hf_token_input = gr.Textbox(label="Введите HF_TOKEN", type="password")
|
28 |
-
submit_button = gr.Button("Сохранить")
|
29 |
-
output_text = gr.Textbox(label="Статус")
|
30 |
-
|
31 |
-
submit_button.click(set_token, inputs=hf_token_input, outputs=output_text)
|
32 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
with gr.Tab("Image Generator"):
|
34 |
with gr.Row():
|
35 |
with gr.Column(scale=10):
|
@@ -67,11 +67,11 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
67 |
with gr.Group():
|
68 |
with gr.Row():
|
69 |
output = [gr.Image(label='', elem_classes="output", type="filepath", format="png",
|
70 |
-
|
71 |
-
|
72 |
with gr.Group():
|
73 |
results = gr.Gallery(label="Gallery", elem_classes="gallery", interactive=False, show_download_button=True, show_share_button=False,
|
74 |
-
|
75 |
image_files = gr.Files(label="Download", interactive=False)
|
76 |
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
77 |
with gr.Column():
|
@@ -120,37 +120,35 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
120 |
|
121 |
gr.on(triggers=[run_button.click, prompt.submit, random_button.click], fn=lambda: gr.update(interactive=True), inputs=None, outputs=stop_button, show_api=False)
|
122 |
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
123 |
-
|
|
|
124 |
for i, o in enumerate(output):
|
125 |
img_i = gr.Number(i, visible=False)
|
126 |
-
image_num.change(lambda i, n: gr.update(visible
|
127 |
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
gen_event2 = gr.on(triggers=[random_button.click],
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
138 |
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
139 |
|
140 |
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
141 |
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
142 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
143 |
-
|
144 |
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
145 |
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
|
151 |
demo.queue(default_concurrency_limit=240, max_size=240)
|
152 |
demo.launch(max_threads=400, ssr_mode=True)
|
153 |
# https://github.com/gradio-app/gradio/issues/6339
|
154 |
|
155 |
demo.queue(concurrency_count=50)
|
156 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
from model import models
|
4 |
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
5 |
+
change_model, warm_model, get_model_info_md, loaded_models,
|
6 |
+
get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
|
7 |
+
get_recom_prompt_type, set_recom_prompt_preset, get_tag_type, randomize_seed, translate_to_en)
|
8 |
+
|
9 |
max_images = 8
|
10 |
MAX_SEED = 2**32-1
|
11 |
load_models(models)
|
|
|
16 |
.gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
|
17 |
"""
|
18 |
|
|
|
19 |
def set_token(token):
|
20 |
+
os.environ["HF_TOKEN"] = token # Сохранение токена в переменной окружения
|
21 |
+
return f"✅ Токен сохранен!"
|
|
|
|
|
|
|
22 |
|
23 |
+
# Основной интерфейс Gradio
|
|
|
|
|
|
|
|
|
|
|
24 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
25 |
+
with gr.Tab("Token Input"): # Новая вкладка для ввода токена
|
26 |
+
gr.Markdown("# 🔑 Введите ваш HF_TOKEN")
|
27 |
+
with gr.Row():
|
28 |
+
token_input = gr.Textbox(label="HF_TOKEN", type="password", placeholder="Введите ваш токен...")
|
29 |
+
save_button = gr.Button("Сохранить")
|
30 |
+
output_text = gr.Textbox(label="Статус", interactive=False)
|
31 |
+
save_button.click(set_token, inputs=[token_input], outputs=[output_text])
|
32 |
+
|
33 |
with gr.Tab("Image Generator"):
|
34 |
with gr.Row():
|
35 |
with gr.Column(scale=10):
|
|
|
67 |
with gr.Group():
|
68 |
with gr.Row():
|
69 |
output = [gr.Image(label='', elem_classes="output", type="filepath", format="png",
|
70 |
+
show_download_button=True, show_share_button=False, show_label=False,
|
71 |
+
interactive=False, min_width=80, visible=True, width=112, height=112) for _ in range(max_images)]
|
72 |
with gr.Group():
|
73 |
results = gr.Gallery(label="Gallery", elem_classes="gallery", interactive=False, show_download_button=True, show_share_button=False,
|
74 |
+
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
75 |
image_files = gr.Files(label="Download", interactive=False)
|
76 |
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
77 |
with gr.Column():
|
|
|
120 |
|
121 |
gr.on(triggers=[run_button.click, prompt.submit, random_button.click], fn=lambda: gr.update(interactive=True), inputs=None, outputs=stop_button, show_api=False)
|
122 |
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
123 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
124 |
+
|
125 |
for i, o in enumerate(output):
|
126 |
img_i = gr.Number(i, visible=False)
|
127 |
+
image_num.change(lambda i, n: gr.update(visible=(i < n)), [img_i, image_num], o, show_api=True)
|
128 |
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
129 |
+
fn=lambda i, n, m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4: infer_fn(m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4) if (i < n) else None,
|
130 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
131 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
132 |
+
outputs=[o], queue=True, show_api=False)
|
133 |
gen_event2 = gr.on(triggers=[random_button.click],
|
134 |
+
fn=lambda i, n, m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4: infer_rand_fn(m, t1, t2, n1, n2, n3, n4, n5, l1, l2, l3, l4) if (i < n) else None,
|
135 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
136 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
137 |
+
outputs=[o], queue=True, show_api=False)
|
138 |
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
139 |
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
140 |
|
141 |
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
142 |
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
143 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
144 |
+
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=True, show_api=True)
|
145 |
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
146 |
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
147 |
+
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True, show_api=True)
|
|
|
|
|
|
|
148 |
|
149 |
demo.queue(default_concurrency_limit=240, max_size=240)
|
150 |
demo.launch(max_threads=400, ssr_mode=True)
|
151 |
# https://github.com/gradio-app/gradio/issues/6339
|
152 |
|
153 |
demo.queue(concurrency_count=50)
|
154 |
+
demo.launch()
|