johann-foerster
commited on
Commit
•
347eac7
1
Parent(s):
45b14e8
do not send original image from client for overlay, but use (log) path on server instead
Browse files- modules/async_worker.py +13 -14
- modules/private_logger.py +1 -1
- webui.py +24 -19
modules/async_worker.py
CHANGED
@@ -54,20 +54,19 @@ def worker():
|
|
54 |
f'{step}/{total_steps}',
|
55 |
y)])
|
56 |
|
57 |
-
img = pipeline.process(p_txt, n_txt, steps, switch, width, height, seed, callback=callback)
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
outputs.append(['results', img])
|
71 |
return
|
72 |
|
73 |
while True:
|
|
|
54 |
f'{step}/{total_steps}',
|
55 |
y)])
|
56 |
|
57 |
+
img = pipeline.process(p_txt, n_txt, steps, switch, width, height, seed, callback=callback)[0]
|
58 |
+
|
59 |
+
d = [
|
60 |
+
('Prompt', prompt),
|
61 |
+
('Style', style_selection),
|
62 |
+
('Seed', seed)
|
63 |
+
]
|
64 |
+
for n, w in loras:
|
65 |
+
if n != 'None':
|
66 |
+
d.append((f'LoRA [{n}] weight', w))
|
67 |
+
img_path=log(img, d)
|
68 |
+
|
69 |
+
outputs.append(['results', [img, img_path]])
|
|
|
70 |
return
|
71 |
|
72 |
while True:
|
modules/private_logger.py
CHANGED
@@ -34,4 +34,4 @@ def log(img, dic):
|
|
34 |
|
35 |
print(f'Image generated with private log at: {html_name}')
|
36 |
|
37 |
-
return
|
|
|
34 |
|
35 |
print(f'Image generated with private log at: {html_name}')
|
36 |
|
37 |
+
return local_temp_filename
|
webui.py
CHANGED
@@ -7,8 +7,8 @@ from PIL import Image, ImageDraw, ImageFont
|
|
7 |
|
8 |
from modules.sdxl_styles import style_keys, aspect_ratios
|
9 |
|
10 |
-
QM_LOGO=Image.open("resources/qm_logo.png")
|
11 |
-
QM_COLOR=Color(name="qm", c50="#effaed",c100="#def5db",c200="#64b445",c300="#c6eec0",c400="#b9ebb3",c500="#64b445",c600="#55993b",c700="#467e30",c800="#325a23",c900="#233f18",c950="#192d11")
|
12 |
PROMPT_EXAMPLES = [["Der Weihnachtsmann mit seinem Sack voller Geschenke", "Santa Claus with his sack full of gifts"],
|
13 |
["Malerisches Winterdorf in einer Schneekugel", "Scenic winter village inside a snow globe"],
|
14 |
["Niedliche Pinguine in Schals und Mützen eingewickelt", "Cute penguins wrapped up in scarves and hats"]]
|
@@ -17,10 +17,12 @@ EXAMPLE_GREETINGS = [
|
|
17 |
"Frohes Fest und viele glückliche Momente mit deinen Liebsten!",
|
18 |
"Zauberhafte Weihnachten für dich!"
|
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)
|
@@ -36,11 +38,13 @@ def generate(*args):
|
|
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
|
42 |
yield gr.HTML(value=""), \
|
43 |
-
gr.Image(value=image)
|
|
|
44 |
finished = True
|
45 |
return
|
46 |
|
@@ -63,8 +67,8 @@ def debounce():
|
|
63 |
time.sleep(0.5)
|
64 |
return
|
65 |
|
66 |
-
def
|
67 |
-
image = ImageDraw.Draw(
|
68 |
HEIGHT, TEXT_PADDING, TEXTBOX_HEIGHT = 100, 32, 56
|
69 |
TEXTBOX_WIDTH = 1280-HEIGHT-4*TEXT_PADDING
|
70 |
|
@@ -86,7 +90,7 @@ 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.Image(value=
|
90 |
|
91 |
def verify_latest_overlay(image, toggle_greet, greet, greet_active):
|
92 |
if greet != greet_active:
|
@@ -141,21 +145,22 @@ with shared.gradio_root:
|
|
141 |
greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
|
142 |
|
143 |
|
144 |
-
|
145 |
-
value=
|
146 |
generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', elem_classes="generated-image", width=1280,
|
147 |
-
value=
|
|
|
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=[
|
152 |
greet.change(fn=debounce, queue=False, show_progress=False)\
|
153 |
-
.then(fn=make_overlay, inputs=[
|
154 |
-
greet_active.change(fn=verify_latest_overlay, inputs=[
|
155 |
-
run_button.click(fn=prepare_generate, outputs=[
|
156 |
-
.then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html,
|
157 |
-
.then(fn=make_overlay, inputs=[
|
158 |
-
.then(fn=finish_generate, outputs=[
|
159 |
|
160 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|
161 |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False)
|
|
|
7 |
|
8 |
from modules.sdxl_styles import style_keys, aspect_ratios
|
9 |
|
10 |
+
QM_LOGO = Image.open("resources/qm_logo.png")
|
11 |
+
QM_COLOR = Color(name="qm", c50="#effaed",c100="#def5db",c200="#64b445",c300="#c6eec0",c400="#b9ebb3",c500="#64b445",c600="#55993b",c700="#467e30",c800="#325a23",c900="#233f18",c950="#192d11")
|
12 |
PROMPT_EXAMPLES = [["Der Weihnachtsmann mit seinem Sack voller Geschenke", "Santa Claus with his sack full of gifts"],
|
13 |
["Malerisches Winterdorf in einer Schneekugel", "Scenic winter village inside a snow globe"],
|
14 |
["Niedliche Pinguine in Schals und Mützen eingewickelt", "Cute penguins wrapped up in scarves and hats"]]
|
|
|
17 |
"Frohes Fest und viele glückliche Momente mit deinen Liebsten!",
|
18 |
"Zauberhafte Weihnachten für dich!"
|
19 |
]
|
20 |
+
INIT_IMAGE_PATH = "resources/init.png"
|
21 |
|
22 |
def generate(*args):
|
23 |
yield gr.HTML(value=modules.html.make_progress_html(1, "0/30")), \
|
24 |
+
gr.Image(), \
|
25 |
+
gr.Text()
|
26 |
|
27 |
while worker.is_working:
|
28 |
time.sleep(0.1)
|
|
|
38 |
if flag == 'preview':
|
39 |
percentage, title, image = product
|
40 |
yield gr.HTML(value=modules.html.make_progress_html(percentage, title)), \
|
41 |
+
gr.Image(value=image) if image is not None else gr.Image(), \
|
42 |
+
gr.Text()
|
43 |
if flag == 'results':
|
44 |
+
image, image_path = product
|
45 |
yield gr.HTML(value=""), \
|
46 |
+
gr.Image(value=image), \
|
47 |
+
gr.Text(value=image_path)
|
48 |
finished = True
|
49 |
return
|
50 |
|
|
|
67 |
time.sleep(0.5)
|
68 |
return
|
69 |
|
70 |
+
def overlay_image(image_path, toggle_greet, greet):
|
71 |
+
image = ImageDraw.Draw(Image.open(image_path), "RGBA")
|
72 |
HEIGHT, TEXT_PADDING, TEXTBOX_HEIGHT = 100, 32, 56
|
73 |
TEXTBOX_WIDTH = 1280-HEIGHT-4*TEXT_PADDING
|
74 |
|
|
|
90 |
return image._image
|
91 |
|
92 |
def make_overlay(image, toggle_greet, greet):
|
93 |
+
return gr.Image(value=overlay_image(image, toggle_greet, greet)), gr.Textbox(value=greet)
|
94 |
|
95 |
def verify_latest_overlay(image, toggle_greet, greet, greet_active):
|
96 |
if greet != greet_active:
|
|
|
145 |
greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
|
146 |
|
147 |
|
148 |
+
generated_image = gr.Image(visible=False, type='pil', label="Erstelle Weihnachtskarte...", elem_classes="generated-image", width=1280,
|
149 |
+
value=INIT_IMAGE_PATH, interactive=False, show_share_button=False, show_download_button=False)
|
150 |
generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', elem_classes="generated-image", width=1280,
|
151 |
+
value=overlay_image(INIT_IMAGE_PATH, toggle_greet.value, greet.value))
|
152 |
+
generated_image_path = gr.Text(visible=False, value=INIT_IMAGE_PATH)
|
153 |
|
154 |
promt_example_de.change(fn=translate_promt_example, inputs=[promt_example_de], outputs=[prompt], queue=False)
|
155 |
toggle_greet.change(fn=toggle_greet_visibility, inputs=[toggle_greet], outputs=[greeting_row], queue=False, show_progress=False)\
|
156 |
+
.then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], show_progress=False, queue=False)
|
157 |
greet.change(fn=debounce, queue=False, show_progress=False)\
|
158 |
+
.then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
|
159 |
+
greet_active.change(fn=verify_latest_overlay, inputs=[generated_image_path, toggle_greet, greet, greet_active], outputs=[generated_image_overlayed, greet_active], queue=False, show_progress=False)
|
160 |
+
run_button.click(fn=prepare_generate, outputs=[generated_image, generated_image_overlayed, run_button], queue=False)\
|
161 |
+
.then(fn=generate, inputs=[prompt, style_selection], outputs=[progress_html, generated_image, generated_image_path], queue=True)\
|
162 |
+
.then(fn=make_overlay, inputs=[generated_image_path, toggle_greet, greet], outputs=[generated_image_overlayed, greet_active], queue=False)\
|
163 |
+
.then(fn=finish_generate, outputs=[generated_image, generated_image_overlayed, run_button], queue=False)
|
164 |
|
165 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|
166 |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False)
|