Spaces:
Paused
Paused
johann-foerster
commited on
Commit
•
41b1d8d
1
Parent(s):
35f1465
more responsive UX
Browse files
webui.py
CHANGED
@@ -19,10 +19,8 @@ EXAMPLE_GREETINGS = [
|
|
19 |
]
|
20 |
|
21 |
def generate(*args):
|
22 |
-
yield gr.update(
|
23 |
-
gr.update(
|
24 |
-
gr.update(visible=True), \
|
25 |
-
gr.update(visible=False)
|
26 |
|
27 |
while worker.is_working:
|
28 |
time.sleep(0.1)
|
@@ -37,16 +35,12 @@ def generate(*args):
|
|
37 |
flag, product = worker.outputs.pop(0)
|
38 |
if flag == 'preview':
|
39 |
percentage, title, image = product
|
40 |
-
yield gr.update(), \
|
41 |
-
gr.update(value=
|
42 |
-
gr.update(value=image) if image is not None else gr.update(), \
|
43 |
-
gr.update()
|
44 |
if flag == 'results':
|
45 |
image = product[0]
|
46 |
-
yield gr.update(
|
47 |
-
gr.update(value=
|
48 |
-
gr.update(visible=False, value=image), \
|
49 |
-
gr.update(visible=True, value=image)
|
50 |
finished = True
|
51 |
return
|
52 |
|
@@ -56,6 +50,15 @@ def translate_promt_example(prompt_de):
|
|
56 |
def toggle_greet_visibility(is_visible):
|
57 |
return gr.update(visible=is_visible)
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def debounce():
|
60 |
time.sleep(0.5)
|
61 |
return gr.update()
|
@@ -116,7 +119,7 @@ with shared.gradio_root:
|
|
116 |
style_selection = gr.Dropdown(choices=style_keys, value='Kinofilm', container=False, elem_id="style-selection")
|
117 |
with gr.Column(scale=1, min_width="80px"):
|
118 |
progress_html = gr.HTML(visible=True, elem_id='progress-bar', elem_classes='progress-bar')
|
119 |
-
run_button = gr.Button(value="Weihnachtskarte\nerstellen", variant='primary', elem_id='generate-button')
|
120 |
with gr.Row():
|
121 |
promt_example_de = gr.Textbox(visible=False)
|
122 |
gr.Examples(elem_id="prompt-examples", examples=PROMPT_EXAMPLES, inputs=[promt_example_de], cache_examples=False)
|
@@ -137,12 +140,14 @@ with shared.gradio_root:
|
|
137 |
value=pil_image_with_overlay(Image.open("resources/init.png"), toggle_greet.value, greet.value))
|
138 |
|
139 |
promt_example_de.change(fn=translate_promt_example, inputs=[promt_example_de], outputs=[prompt], queue=False)
|
140 |
-
toggle_greet.change(fn=toggle_greet_visibility, inputs=[toggle_greet], outputs=[greeting_row], queue=False)\
|
141 |
-
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
142 |
-
greet.change(fn=debounce, outputs=[generated_image_overlayed], queue=False)\
|
143 |
-
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
144 |
-
run_button.click(fn=
|
145 |
-
.then(fn=
|
|
|
|
|
146 |
|
147 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|
148 |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False)
|
|
|
19 |
]
|
20 |
|
21 |
def generate(*args):
|
22 |
+
yield gr.update(value=modules.html.make_progress_html(1, "0/30")), \
|
23 |
+
gr.update()
|
|
|
|
|
24 |
|
25 |
while worker.is_working:
|
26 |
time.sleep(0.1)
|
|
|
35 |
flag, product = worker.outputs.pop(0)
|
36 |
if flag == 'preview':
|
37 |
percentage, title, image = product
|
38 |
+
yield gr.update(value=modules.html.make_progress_html(percentage, title)), \
|
39 |
+
gr.update(value=image) if image is not None else gr.update()
|
|
|
|
|
40 |
if flag == 'results':
|
41 |
image = product[0]
|
42 |
+
yield gr.update(value=""), \
|
43 |
+
gr.update(value=image)
|
|
|
|
|
44 |
finished = True
|
45 |
return
|
46 |
|
|
|
50 |
def toggle_greet_visibility(is_visible):
|
51 |
return gr.update(visible=is_visible)
|
52 |
|
53 |
+
def __toggle_generate_state(is_preview):
|
54 |
+
return gr.update(visible=is_preview), gr.update(visible=not is_preview), gr.update(interactive=not is_preview)
|
55 |
+
|
56 |
+
def prepare_generate():
|
57 |
+
return __toggle_generate_state(True)
|
58 |
+
|
59 |
+
def finish_generate():
|
60 |
+
return __toggle_generate_state(False)
|
61 |
+
|
62 |
def debounce():
|
63 |
time.sleep(0.5)
|
64 |
return gr.update()
|
|
|
119 |
style_selection = gr.Dropdown(choices=style_keys, value='Kinofilm', container=False, elem_id="style-selection")
|
120 |
with gr.Column(scale=1, min_width="80px"):
|
121 |
progress_html = gr.HTML(visible=True, elem_id='progress-bar', elem_classes='progress-bar')
|
122 |
+
run_button = gr.Button(value="Weihnachtskarte\nerstellen", variant='primary', elem_id='generate-button', )
|
123 |
with gr.Row():
|
124 |
promt_example_de = gr.Textbox(visible=False)
|
125 |
gr.Examples(elem_id="prompt-examples", examples=PROMPT_EXAMPLES, inputs=[promt_example_de], cache_examples=False)
|
|
|
140 |
value=pil_image_with_overlay(Image.open("resources/init.png"), toggle_greet.value, greet.value))
|
141 |
|
142 |
promt_example_de.change(fn=translate_promt_example, inputs=[promt_example_de], outputs=[prompt], queue=False)
|
143 |
+
toggle_greet.change(fn=toggle_greet_visibility, inputs=[toggle_greet], outputs=[greeting_row], queue=False, show_progress=False)\
|
144 |
+
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], show_progress=False, queue=False)
|
145 |
+
greet.change(fn=debounce, outputs=[generated_image_overlayed], queue=False, show_progress=False)\
|
146 |
+
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False, show_progress=False)
|
147 |
+
run_button.click(fn=prepare_generate, outputs=[generated_image_raw, generated_image_overlayed, run_button], queue=False)\
|
148 |
+
.then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html, generated_image_raw], queue=True)\
|
149 |
+
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)\
|
150 |
+
.then(fn=finish_generate, outputs=[generated_image_raw, generated_image_overlayed, run_button], queue=False)
|
151 |
|
152 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|
153 |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False)
|