Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
44 |
with gr.Row():
|
45 |
run_button = gr.Button("Generate Image", variant="primary", scale=6)
|
46 |
random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
|
47 |
-
|
48 |
with gr.Group():
|
49 |
model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
|
50 |
model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
|
@@ -104,32 +104,33 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css) as demo:
|
|
104 |
gr.Markdown(f"Just a few edits to *model.py* are all it takes to complete your own collection.")
|
105 |
|
106 |
#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)
|
107 |
-
model_name.change(change_model, [model_name], [model_info], queue=
|
108 |
-
.success(warm_model, [model_name], None, queue=
|
109 |
for i, o in enumerate(output):
|
110 |
img_i = gr.Number(i, visible=False)
|
111 |
-
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=
|
112 |
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
113 |
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,
|
114 |
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
115 |
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
116 |
-
outputs=[o], queue=
|
117 |
gen_event2 = gr.on(triggers=[random_button.click],
|
118 |
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,
|
119 |
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
120 |
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
121 |
-
outputs=[o], queue=
|
122 |
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
123 |
#stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
124 |
|
125 |
-
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=
|
126 |
-
clear_results.click(lambda: (None, None), None, [results, image_files], queue=
|
127 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
128 |
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=False, show_api=False)
|
129 |
seed_rand.click(randomize_seed, None, [seed], queue=False, show_api=False)
|
130 |
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=False, show_api=False)\
|
131 |
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=False, show_api=False)
|
132 |
|
133 |
-
|
|
|
134 |
demo.launch(max_threads=400, ssr_mode=False)
|
135 |
# https://github.com/gradio-app/gradio/issues/6339
|
|
|
44 |
with gr.Row():
|
45 |
run_button = gr.Button("Generate Image", variant="primary", scale=6)
|
46 |
random_button = gr.Button("Random Model 🎲", variant="secondary", scale=3)
|
47 |
+
stop_button = gr.Button('Stop', interactive=False, variant="stop", scale=1)
|
48 |
with gr.Group():
|
49 |
model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
|
50 |
model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]), elem_classes="model_info")
|
|
|
104 |
gr.Markdown(f"Just a few edits to *model.py* are all it takes to complete your own collection.")
|
105 |
|
106 |
#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)
|
107 |
+
model_name.change(change_model, [model_name], [model_info], queue=True, show_api=True)\
|
108 |
+
.success(warm_model, [model_name], None, queue=True, show_api=True)
|
109 |
for i, o in enumerate(output):
|
110 |
img_i = gr.Number(i, visible=False)
|
111 |
+
image_num.change(lambda i, n: gr.update(visible = (i < n)), [img_i, image_num], o, show_api=True)
|
112 |
gen_event = gr.on(triggers=[run_button.click, prompt.submit],
|
113 |
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,
|
114 |
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
115 |
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
116 |
+
outputs=[o], queue=True, show_api=True) # Be sure to delete ", queue=False" when activating the stop button
|
117 |
gen_event2 = gr.on(triggers=[random_button.click],
|
118 |
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,
|
119 |
inputs=[img_i, image_num, model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
120 |
positive_prefix, positive_suffix, negative_prefix, negative_suffix],
|
121 |
+
outputs=[o], queue=True, show_api=True) # Be sure to delete ", queue=False" when activating the stop button
|
122 |
o.change(save_gallery, [o, results], [results, image_files], show_api=False)
|
123 |
#stop_button.click(lambda: gr.update(interactive=False), None, stop_button, cancels=[gen_event, gen_event2], show_api=False)
|
124 |
|
125 |
+
clear_prompt.click(lambda: (None, None), None, [prompt, neg_prompt], queue=True, show_api=False)
|
126 |
+
clear_results.click(lambda: (None, None), None, [results, image_files], queue=True, show_api=False)
|
127 |
recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
|
128 |
[positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=False, show_api=False)
|
129 |
seed_rand.click(randomize_seed, None, [seed], queue=False, show_api=False)
|
130 |
trans_prompt.click(translate_to_en, [prompt], [prompt], queue=False, show_api=False)\
|
131 |
.then(translate_to_en, [neg_prompt], [neg_prompt], queue=False, show_api=False)
|
132 |
|
133 |
+
demo.queue(concurrency_count=150)
|
134 |
+
#demo.queue(default_concurrency_limit=240, max_size=240)
|
135 |
demo.launch(max_threads=400, ssr_mode=False)
|
136 |
# https://github.com/gradio-app/gradio/issues/6339
|