Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
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 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
max_images = 8
|
10 |
MAX_SEED = 2**32-1
|
@@ -16,20 +15,7 @@ css = """
|
|
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,11 +53,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,35 +106,37 @@ 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 |
-
|
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 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
gen_event2 = gr.on(triggers=[random_button.click],
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
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 |
-
|
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 |
-
|
|
|
|
|
|
|
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()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from model import models
|
3 |
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
4 |
+
change_model, warm_model, get_model_info_md, loaded_models,
|
5 |
+
get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
|
6 |
+
get_recom_prompt_type, set_recom_prompt_preset, get_tag_type, randomize_seed, translate_to_en)
|
7 |
|
8 |
max_images = 8
|
9 |
MAX_SEED = 2**32-1
|
|
|
15 |
.gallery { min_width=512px; min_height=512px; max_height=1024px; !important; }
|
16 |
"""
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
with gr.Tab("Image Generator"):
|
20 |
with gr.Row():
|
21 |
with gr.Column(scale=10):
|
|
|
53 |
with gr.Group():
|
54 |
with gr.Row():
|
55 |
output = [gr.Image(label='', elem_classes="output", type="filepath", format="png",
|
56 |
+
show_download_button=True, show_share_button=False, show_label=False,
|
57 |
+
interactive=False, min_width=80, visible=True, width=112, height=112) for _ in range(max_images)]
|
58 |
with gr.Group():
|
59 |
results = gr.Gallery(label="Gallery", elem_classes="gallery", interactive=False, show_download_button=True, show_share_button=False,
|
60 |
+
container=True, format="png", object_fit="cover", columns=2, rows=2)
|
61 |
image_files = gr.Files(label="Download", interactive=False)
|
62 |
clear_results = gr.Button("Clear Gallery / Download 🗑️", variant="secondary")
|
63 |
with gr.Column():
|
|
|
106 |
|
107 |
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)
|
108 |
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
109 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
|
|
110 |
for i, o in enumerate(output):
|
111 |
img_i = gr.Number(i, visible=False)
|
112 |
+
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=True)
|
113 |
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
114 |
+
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,
|
115 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
116 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
117 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
118 |
gen_event2 = gr.on(triggers=[random_button.click],
|
119 |
+
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,
|
120 |
+
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
121 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
122 |
+
outputs=[o], queue=True, show_api=False) # Be sure to delete ", queue=False" when activating the stop button
|
123 |
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
124 |
stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
125 |
|
126 |
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=True)
|
127 |
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=True)
|
128 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
129 |
+
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=True, show_api=True)
|
130 |
seed_rand.click(randomize_seed, None, [seed], queue=True, show_api=True)
|
131 |
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=True, show_api=True)\
|
132 |
+
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=True, show_api=True)
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
|
137 |
demo.queue(default_concurrency_limit=240, max_size=240)
|
138 |
demo.launch(max_threads=400, ssr_mode=True)
|
139 |
# https://github.com/gradio-app/gradio/issues/6339
|
140 |
|
141 |
demo.queue(concurrency_count=50)
|
142 |
+
demo.launch()
|