Commit
·
cc1aefe
1
Parent(s):
086d94f
UI improvements, gradio update
Browse files- modules/html.py +62 -21
- requirements_versions.txt +1 -1
- webui.py +60 -57
modules/html.py
CHANGED
|
@@ -26,7 +26,7 @@ progress {
|
|
| 26 |
border-radius: 5px; /* Round the corners of the progress bar */
|
| 27 |
background-color: #f3f3f3; /* Light grey background */
|
| 28 |
width: 100%;
|
| 29 |
-
margin-top:
|
| 30 |
}
|
| 31 |
|
| 32 |
/* Style the progress bar container */
|
|
@@ -65,56 +65,97 @@ progress::after {
|
|
| 65 |
display: none !important;
|
| 66 |
}
|
| 67 |
|
| 68 |
-
|
| 69 |
-
height:
|
| 70 |
}
|
| 71 |
|
| 72 |
.stylebox{
|
| 73 |
min-height: 110px !important;
|
| 74 |
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
white-space: pre-line !important;
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
.stylebox label span {
|
| 83 |
margin-bottom: 22px !important;
|
| 84 |
}
|
| 85 |
|
| 86 |
-
.scroll-hide{
|
| 87 |
resize: none !important;
|
| 88 |
}
|
| 89 |
|
| 90 |
-
.
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
font-size: none !important;
|
| 94 |
-
box-shadow: none !important;
|
| 95 |
}
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
-
.
|
| 102 |
-
|
| 103 |
}
|
| 104 |
|
| 105 |
-
.
|
| 106 |
-
|
| 107 |
}
|
| 108 |
|
| 109 |
-
.
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
|
| 114 |
#toggle-greet-checkbox span {
|
| 115 |
font-size: 1.05em !important;
|
| 116 |
font-weight: var(--prose-header-text-weight) !important;
|
| 117 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
'''
|
| 119 |
progress_html = '''
|
| 120 |
<div class="loader-container" style="visibility:*visibility*;max-width:1280px;">
|
|
|
|
| 26 |
border-radius: 5px; /* Round the corners of the progress bar */
|
| 27 |
background-color: #f3f3f3; /* Light grey background */
|
| 28 |
width: 100%;
|
| 29 |
+
margin-top: 5px;
|
| 30 |
}
|
| 31 |
|
| 32 |
/* Style the progress bar container */
|
|
|
|
| 65 |
display: none !important;
|
| 66 |
}
|
| 67 |
|
| 68 |
+
#progress-bar {
|
| 69 |
+
height: 22px !important;
|
| 70 |
}
|
| 71 |
|
| 72 |
.stylebox{
|
| 73 |
min-height: 110px !important;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
#generate-button {
|
| 77 |
+
height: 60px !important;
|
| 78 |
white-space: pre-line !important;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
#style-selection input {
|
| 82 |
+
min-height: 39px !important;
|
| 83 |
}
|
| 84 |
|
| 85 |
.stylebox label span {
|
| 86 |
margin-bottom: 22px !important;
|
| 87 |
}
|
| 88 |
|
| 89 |
+
.scroll-hide {
|
| 90 |
resize: none !important;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
.input-label h5 {
|
| 94 |
+
margin: 0 !important;
|
| 95 |
+
padding-top: 3px !important;
|
|
|
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
+
.icon-buttons > a > button > div, .icon-buttons > button > div {
|
| 99 |
+
width: 2em;
|
| 100 |
+
height: 2em;
|
| 101 |
}
|
| 102 |
|
| 103 |
+
.stretch {
|
| 104 |
+
column-gap: 0 !important;
|
| 105 |
}
|
| 106 |
|
| 107 |
+
.gap {
|
| 108 |
+
row-gap: 6px !important;
|
| 109 |
}
|
| 110 |
|
| 111 |
+
.gallery {
|
| 112 |
+
row-gap: 2px !important;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
#prompt-examples .label, #greet-examples .label {
|
| 116 |
+
display: none;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#prompt-examples > .gallery::before, #greet-examples > .gallery::before {
|
| 120 |
+
content: "Beispiele";
|
| 121 |
+
font-size: 1.05em;
|
| 122 |
+
font-weight: var(--prose-header-text-weight);
|
| 123 |
+
padding-top: 0.33em;
|
| 124 |
}
|
| 125 |
|
| 126 |
#toggle-greet-checkbox span {
|
| 127 |
font-size: 1.05em !important;
|
| 128 |
font-weight: var(--prose-header-text-weight) !important;
|
| 129 |
}
|
| 130 |
+
|
| 131 |
+
.panel-container {
|
| 132 |
+
box-shadow: var(--block-shadow);
|
| 133 |
+
border: var(--block-border-width) solid var(--border-color-primary);
|
| 134 |
+
border-radius: var(--block-radius);
|
| 135 |
+
padding: 5px;
|
| 136 |
+
max-width: 1280px;
|
| 137 |
+
margin-bottom: 10px !important;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.label-wrap {
|
| 141 |
+
justify-content: start !important;
|
| 142 |
+
margin-bottom: 0 !important;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.label-wrap .icon {
|
| 146 |
+
padding-top: 5px !important;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.label-wrap span{
|
| 150 |
+
font-size: 1.05em !important;
|
| 151 |
+
font-weight: var(--prose-header-text-weight) !important;
|
| 152 |
+
padding-right: 5px;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.generated-image img {
|
| 156 |
+
width: 1280px !important;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
'''
|
| 160 |
progress_html = '''
|
| 161 |
<div class="loader-container" style="visibility:*visibility*;max-width:1280px;">
|
requirements_versions.txt
CHANGED
|
@@ -11,5 +11,5 @@ psutil==5.9.5
|
|
| 11 |
numpy==1.23.5
|
| 12 |
pytorch_lightning==1.9.4
|
| 13 |
omegaconf==2.2.3
|
| 14 |
-
gradio==3.
|
| 15 |
pygit2==1.12.2
|
|
|
|
| 11 |
numpy==1.23.5
|
| 12 |
pytorch_lightning==1.9.4
|
| 13 |
omegaconf==2.2.3
|
| 14 |
+
gradio==3.45.1
|
| 15 |
pygit2==1.12.2
|
webui.py
CHANGED
|
@@ -9,10 +9,18 @@ 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 |
|
| 13 |
def generate(*args):
|
| 14 |
yield gr.update(interactive=False), \
|
| 15 |
-
gr.update(
|
| 16 |
gr.update(visible=True), \
|
| 17 |
gr.update(visible=False)
|
| 18 |
|
|
@@ -36,14 +44,17 @@ def generate(*args):
|
|
| 36 |
if flag == 'results':
|
| 37 |
image = product[0]
|
| 38 |
yield gr.update(interactive=True), \
|
| 39 |
-
gr.update(
|
| 40 |
gr.update(visible=False, value=image), \
|
| 41 |
-
gr.update(visible=True)
|
| 42 |
finished = True
|
| 43 |
return
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
def toggle_greet_visibility(is_visible):
|
| 46 |
-
return gr.update(visible=is_visible)
|
| 47 |
|
| 48 |
def debounce():
|
| 49 |
time.sleep(0.5)
|
|
@@ -80,66 +91,58 @@ with shared.gradio_root:
|
|
| 80 |
"""
|
| 81 |
# QualityMinds KI Weihnachtskarten-Generator
|
| 82 |
""")
|
| 83 |
-
with gr.
|
| 84 |
-
with gr.Column(
|
| 85 |
-
gr.Markdown("
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
with gr.Column(
|
| 97 |
-
gr.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
with greet_examples_column:
|
| 116 |
-
gr.Markdown("##### Beispiele", elem_classes="input-label")
|
| 117 |
-
greet_examples = gr.Examples(label="Beispiele", examples=example_texts, inputs=[greet],
|
| 118 |
-
elem_id="greet-examples")
|
| 119 |
-
|
| 120 |
-
generated_image_raw = gr.Image(visible=False, type='pil', label="Erstelle Weihnachtskarte...", width=1280,
|
| 121 |
-
value="resources/init.png", interactive=False,
|
| 122 |
-
show_share_button=False, show_download_button=False )
|
| 123 |
-
generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', width=1280,
|
| 124 |
value=pil_image_with_overlay(Image.open("resources/init.png"), toggle_greet.value, greet.value))
|
| 125 |
|
| 126 |
-
|
|
|
|
| 127 |
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
| 128 |
greet.change(fn=debounce, outputs=[generated_image_overlayed], queue=False)\
|
| 129 |
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
| 130 |
-
run_button.click(fn=generate, inputs=[prompt, style_selection], outputs=[run_button, progress_html, generated_image_raw, generated_image_overlayed])\
|
| 131 |
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
| 132 |
|
| 133 |
-
gr.Markdown("""
|
| 134 |
-
## Info
|
| 135 |
-
* Beschreibe das Motiv der Weihnachtskarte in einem Prompt (Englisch), wähle ggf. Stil und los!
|
| 136 |
-
* Zur Übersetzung einer Beschreibung ins Englische eignet sich beispielsweise [deepl.com](https://www.deepl.com/translator#de/Schneekugeln) helfen.
|
| 137 |
-
* Chat-KIs wie [Bing Chat](https://www.bing.com/search?q=Bing+AI&showconv=1) können bei der Erstellung persönlicher Weihnachtsgrüße helfen, z.B. mit Prompts wie
|
| 138 |
-
* Erstelle fünf unterschiedliche persönliche Weihnachtsgrüße für meinen Vater Anakin (je ca. 120 Zeichen). Erwähne dabei unseren gemeinsamen Urlaub auf Tatooine.
|
| 139 |
-
* Erstelle drei unterschiedliche persönliche Weihnachtsgrüße für meinen geschätzten Arbeitskollegen Michael (je ca. 150 Zeichen). Gehe dabei Schritt für Schritt vor.
|
| 140 |
-
* Erstelle fünf unterschiedliche persönliche Weihnachtsgrüße für eine Weihnachtskarte, auf der eine Schneekugel abgebildet ist (je ca. 133 Zeichen) und erkläre diese.
|
| 141 |
-
* Dieses Werkzeug basiert auf [Stable Diffusion XL](https://stability.ai/stable-diffusion) v1.0 und der Oberfläche [Fooocus](https://github.com/lllyasviel/Fooocus), der Code ist OpenSource auf [HuggingFace](https://huggingface.co/spaces/QualityMinds/Weihnachtskarten/tree/main) verfügbar.
|
| 142 |
-
""")
|
| 143 |
-
|
| 144 |
shared.gradio_root.queue(concurrency_count=1, api_open=False)
|
| 145 |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False)
|
|
|
|
| 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"]]
|
| 15 |
+
EXAMPLE_GREETINGS = [
|
| 16 |
+
"Ich wünsche dir von Herzen ein frohes Weihnachtsfest.",
|
| 17 |
+
"Frohe Weihnachten und viele glückliche Momente mit deinen Liebsten!",
|
| 18 |
+
"Zauberhafte Weihnachten für dich!"
|
| 19 |
+
]
|
| 20 |
|
| 21 |
def generate(*args):
|
| 22 |
yield gr.update(interactive=False), \
|
| 23 |
+
gr.update(value=modules.html.make_progress_html(1, "0/30")), \
|
| 24 |
gr.update(visible=True), \
|
| 25 |
gr.update(visible=False)
|
| 26 |
|
|
|
|
| 44 |
if flag == 'results':
|
| 45 |
image = product[0]
|
| 46 |
yield gr.update(interactive=True), \
|
| 47 |
+
gr.update(value=""), \
|
| 48 |
gr.update(visible=False, value=image), \
|
| 49 |
+
gr.update(visible=True, value=image)
|
| 50 |
finished = True
|
| 51 |
return
|
| 52 |
|
| 53 |
+
def translate_promt_example(prompt_de):
|
| 54 |
+
return [x for x in PROMPT_EXAMPLES if x[0] == prompt_de][0][1]
|
| 55 |
+
|
| 56 |
def toggle_greet_visibility(is_visible):
|
| 57 |
+
return gr.update(visible=is_visible)
|
| 58 |
|
| 59 |
def debounce():
|
| 60 |
time.sleep(0.5)
|
|
|
|
| 91 |
"""
|
| 92 |
# QualityMinds KI Weihnachtskarten-Generator
|
| 93 |
""")
|
| 94 |
+
with gr.Accordion("Info", elem_classes='panel-container', open=False):
|
| 95 |
+
with gr.Column():
|
| 96 |
+
gr.Markdown("""
|
| 97 |
+
* Beschreibe das Motiv der Weihnachtskarte in einem Prompt (Englisch), wähle ggf. Stil und los!
|
| 98 |
+
* Zur Übersetzung einer Beschreibung ins Englische eignet sich beispielsweise [deepl.com](https://www.deepl.com/translator#de/Schneekugeln) helfen.
|
| 99 |
+
* Chat-KIs wie [Bing Chat](https://www.bing.com/search?q=Bing+AI&showconv=1) können bei der Erstellung persönlicher Weihnachtsgrüße helfen, z.B. mit Prompts wie
|
| 100 |
+
* Erstelle fünf unterschiedliche persönliche Weihnachtsgrüße für meinen Vater Anakin (je ca. 120 Zeichen). Erwähne dabei unseren gemeinsamen Urlaub auf Tatooine.
|
| 101 |
+
* Erstelle drei unterschiedliche persönliche Weihnachtsgrüße für meinen geschätzten Arbeitskollegen Michael (je ca. 150 Zeichen). Gehe dabei Schritt für Schritt vor.
|
| 102 |
+
* Erstelle fünf unterschiedliche persönliche Weihnachtsgrüße für eine Weihnachtskarte, auf der eine Schneekugel abgebildet ist (je ca. 133 Zeichen) und erkläre diese.
|
| 103 |
+
* Dieses Werkzeug basiert auf [Stable Diffusion XL](https://stability.ai/stable-diffusion) v1.0 und der Oberfläche [Fooocus](https://github.com/lllyasviel/Fooocus), der Code ist OpenSource auf [HuggingFace](https://huggingface.co/spaces/QualityMinds/Weihnachtskarten/tree/main) verfügbar.
|
| 104 |
+
""")
|
| 105 |
+
|
| 106 |
+
with gr.Row(elem_classes='panel-container'):
|
| 107 |
+
with gr.Column():
|
| 108 |
+
with gr.Row():
|
| 109 |
+
with gr.Column(scale=5):
|
| 110 |
+
gr.Markdown("##### Prompt (Englisch)", elem_classes="input-label")
|
| 111 |
+
prompt = gr.Textbox(label="Prompt (Englisch)", value="",
|
| 112 |
+
placeholder="Was möchtest Du auf der Weihnachtskarte abbilden?",
|
| 113 |
+
autofocus=True, container=False, lines=2)
|
| 114 |
+
with gr.Column(scale=1, min_width="80px"):
|
| 115 |
+
gr.Markdown("##### Stil", elem_classes="input-label")
|
| 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)
|
| 123 |
|
| 124 |
+
toggle_greet = gr.Checkbox(label="Persönliche Weihnachtsgrüße hinzufügen", elem_id="toggle-greet-checkbox",
|
| 125 |
+
container=False, value=True, interactive=True)
|
| 126 |
+
|
| 127 |
+
greeting_row=gr.Row(elem_classes='panel-container')
|
| 128 |
+
with greeting_row:
|
| 129 |
+
with gr.Column():
|
| 130 |
+
greet = gr.Textbox(value=EXAMPLE_GREETINGS[0], placeholder="", interactive=True, container=False, lines=2, max_lines=2)
|
| 131 |
+
greet_examples = gr.Examples(elem_id="greet-examples", examples=EXAMPLE_GREETINGS, inputs=[greet])
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
generated_image_raw = gr.Image(visible=False, type='pil', label="Erstelle Weihnachtskarte...", elem_classes="generated-image", width=1280,
|
| 135 |
+
value="resources/init.png", interactive=False, show_share_button=False, show_download_button=False)
|
| 136 |
+
generated_image_overlayed = gr.Image(label="Weihnachtskarte", type='pil', elem_classes="generated-image", width=1280,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=generate, inputs=[prompt, style_selection], outputs=[run_button, progress_html, generated_image_raw, generated_image_overlayed], show_progress=False)\
|
| 145 |
.then(fn=make_overlay, inputs=[generated_image_raw, toggle_greet, greet], outputs=[generated_image_overlayed], queue=False)
|
| 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)
|