Spaces:
Paused
Paused
johann-foerster
commited on
Commit
·
1291091
1
Parent(s):
8a5d00f
return new objects instead gr.update; self check latest entry in persönliche weihnachtsgrüße
Browse files
webui.py
CHANGED
@@ -19,8 +19,8 @@ EXAMPLE_GREETINGS = [
|
|
19 |
]
|
20 |
|
21 |
def generate(*args):
|
22 |
-
yield gr.
|
23 |
-
gr.
|
24 |
|
25 |
while worker.is_working:
|
26 |
time.sleep(0.1)
|
@@ -35,12 +35,12 @@ def generate(*args):
|
|
35 |
flag, product = worker.outputs.pop(0)
|
36 |
if flag == 'preview':
|
37 |
percentage, title, image = product
|
38 |
-
yield gr.
|
39 |
-
gr.
|
40 |
if flag == 'results':
|
41 |
image = product[0]
|
42 |
-
yield gr.
|
43 |
-
gr.
|
44 |
finished = True
|
45 |
return
|
46 |
|
@@ -48,10 +48,10 @@ def translate_promt_example(prompt_de):
|
|
48 |
return [x for x in PROMPT_EXAMPLES if x[0] == prompt_de][0][1]
|
49 |
|
50 |
def toggle_greet_visibility(is_visible):
|
51 |
-
return gr.
|
52 |
|
53 |
def __toggle_generate_state(is_preview):
|
54 |
-
return gr.
|
55 |
|
56 |
def prepare_generate():
|
57 |
return __toggle_generate_state(True)
|
@@ -60,8 +60,8 @@ def finish_generate():
|
|
60 |
return __toggle_generate_state(False)
|
61 |
|
62 |
def debounce():
|
63 |
-
time.sleep(
|
64 |
-
return
|
65 |
|
66 |
def pil_image_with_overlay(pil_image, toggle_greet, greet):
|
67 |
image = ImageDraw.Draw(pil_image, "RGBA")
|
@@ -86,7 +86,13 @@ def pil_image_with_overlay(pil_image, toggle_greet, greet):
|
|
86 |
return image._image
|
87 |
|
88 |
def make_overlay(image, toggle_greet, greet):
|
89 |
-
return gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
shared.gradio_root = gr.Blocks(title='QualityMinds AI Christmas Card Maker', css=modules.html.css, theme=gr.themes.Default(primary_hue=QM_COLOR))
|
92 |
with shared.gradio_root:
|
@@ -131,6 +137,7 @@ with shared.gradio_root:
|
|
131 |
with greeting_row:
|
132 |
with gr.Column():
|
133 |
greet = gr.Textbox(value=EXAMPLE_GREETINGS[0], placeholder="", interactive=True, container=False, lines=2, max_lines=2)
|
|
|
134 |
greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
|
135 |
|
136 |
|
@@ -141,12 +148,12 @@ with shared.gradio_root:
|
|
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=
|
146 |
-
|
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)
|
|
|
19 |
]
|
20 |
|
21 |
def generate(*args):
|
22 |
+
yield gr.HTML(value=modules.html.make_progress_html(1, "0/30")), \
|
23 |
+
gr.Image()
|
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.HTML(value=modules.html.make_progress_html(percentage, title)), \
|
39 |
+
gr.Image(value=image) if image is not None else gr.Image()
|
40 |
if flag == 'results':
|
41 |
image = product[0]
|
42 |
+
yield gr.HTML(value=""), \
|
43 |
+
gr.Image(value=image)
|
44 |
finished = True
|
45 |
return
|
46 |
|
|
|
48 |
return [x for x in PROMPT_EXAMPLES if x[0] == prompt_de][0][1]
|
49 |
|
50 |
def toggle_greet_visibility(is_visible):
|
51 |
+
return gr.Row(visible=is_visible)
|
52 |
|
53 |
def __toggle_generate_state(is_preview):
|
54 |
+
return gr.Image(visible=is_preview), gr.Image(visible=not is_preview), gr.Button(interactive=not is_preview)
|
55 |
|
56 |
def prepare_generate():
|
57 |
return __toggle_generate_state(True)
|
|
|
60 |
return __toggle_generate_state(False)
|
61 |
|
62 |
def debounce():
|
63 |
+
time.sleep(5)
|
64 |
+
return
|
65 |
|
66 |
def pil_image_with_overlay(pil_image, toggle_greet, greet):
|
67 |
image = ImageDraw.Draw(pil_image, "RGBA")
|
|
|
86 |
return image._image
|
87 |
|
88 |
def make_overlay(image, toggle_greet, greet):
|
89 |
+
return gr.Image(value=pil_image_with_overlay(image, toggle_greet, greet)), gr.Textbox(value=greet)
|
90 |
+
|
91 |
+
def verify_latest_overlay(image, toggle_greet, greet, greet_active):
|
92 |
+
if greet != greet_active:
|
93 |
+
return make_overlay(image, toggle_greet, greet)
|
94 |
+
else:
|
95 |
+
return gr.Image(), gr.Textbox()
|
96 |
|
97 |
shared.gradio_root = gr.Blocks(title='QualityMinds AI Christmas Card Maker', css=modules.html.css, theme=gr.themes.Default(primary_hue=QM_COLOR))
|
98 |
with shared.gradio_root:
|
|
|
137 |
with greeting_row:
|
138 |
with gr.Column():
|
139 |
greet = gr.Textbox(value=EXAMPLE_GREETINGS[0], placeholder="", interactive=True, container=False, lines=2, max_lines=2)
|
140 |
+
greet_active = gr.Textbox(value=EXAMPLE_GREETINGS[0], visible=False)
|
141 |
greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
|
142 |
|
143 |
|
|
|
148 |
|
149 |
promt_example_de.change(fn=translate_promt_example, inputs=[promt_example_de], outputs=[prompt], queue=False)
|
150 |
toggle_greet.change(fn=toggle_greet_visibility, inputs=[toggle_greet], outputs=[greeting_row], queue=False, show_progress=False)\
|
151 |
+
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], show_progress=False, queue=False)
|
152 |
+
greet.change(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
|
153 |
+
greet_active.change(fn=verify_latest_overlay, inputs=[generated_image_raw, toggle_greet, greet, greet_active], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
|
154 |
run_button.click(fn=prepare_generate, outputs=[generated_image_raw, generated_image_overlayed, run_button], queue=False)\
|
155 |
.then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html, generated_image_raw], queue=True)\
|
156 |
+
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False)\
|
157 |
.then(fn=finish_generate, outputs=[generated_image_raw, generated_image_overlayed, run_button], queue=False)
|
158 |
|
159 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|