Spaces:
Paused
Paused
import gradio as gr | |
from gradio.themes.utils.colors import Color | |
import random | |
import time | |
import shared | |
import argparse | |
import modules.path | |
import fooocus_version | |
import modules.html | |
import modules.async_worker as worker | |
from modules.sdxl_styles import style_keys, aspect_ratios | |
def generate(*args): | |
yield gr.update(interactive=False), \ | |
gr.update(visible=True, value=modules.html.make_progress_html(1, "0/30")), \ | |
gr.update() | |
while worker.is_working: | |
time.sleep(0.1) | |
worker.buffer=[list(args)] | |
worker.outputs = [] | |
finished=False | |
while not finished: | |
time.sleep(0.01) | |
if len(worker.outputs) > 0: | |
flag, product = worker.outputs.pop(0) | |
if flag == 'preview': | |
percentage, title, image = product | |
yield gr.update(interactive=False), \ | |
gr.update(value=modules.html.make_progress_html(percentage, title)), \ | |
gr.update(value=image) if image is not None else gr.update() | |
if flag == 'results': | |
image = product[0] | |
yield gr.update(interactive=True), \ | |
gr.update(visible=False), \ | |
gr.update(value=image) | |
finished = True | |
return | |
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") | |
shared.gradio_root = gr.Blocks(title='QualityMinds AI Christmas Card Maker', css=modules.html.css, theme=gr.themes.Default(primary_hue=qm_color)) | |
with shared.gradio_root: | |
gr.Markdown( | |
""" | |
# QualityMinds KI Weihnachtskarten-Generator | |
* Beschreibe das Motiv der Weihnachtskarte in einem Prompt (Englisch), wähle einen Stil und generiere! | |
* Zur Übersetzung einer Beschreibung ins Englische kann beispielsweise [deepl.com](https://www.deepl.com/translator#de/Schneekugeln) helfen. | |
* Das Tool 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 [Github](https://github.com/QualityMinds/AI-Christmas-Cards) verfügbar. | |
""") | |
with gr.Row(elem_classes='type_row'): | |
with gr.Column(scale=2): | |
gr.Markdown("##### Prompt (Englisch)", elem_classes="input-label") | |
prompt = gr.Textbox(label="Prompt (Englisch)", value="", placeholder="Was möchtest Du auf der Weihnachtskarte abbilden?", | |
autofocus=True, elem_classes='type_row', container=False, lines=2) | |
description_de = gr.Textbox(label="Beschreibung", visible=False) | |
gr.Markdown("##### Beispiele", elem_classes="input-label") | |
gr.Examples(examples=[["Der Weihnachtsmann mit seinem Sack voller Geschenke", "Santa Claus with his sack full of gifts"], | |
["Malerisches Winterdorf in einer Schneekugel", "Scenic winter village inside a snow globe"], | |
["Niedliche Pinguine in Schals und Mützen eingewickelt", "Cute penguins wrapped up in scarves and hats"]], | |
inputs=[description_de, prompt], elem_id="prompt_examples", cache_examples=False) | |
with gr.Column(scale=1, min_width="120px"): | |
gr.Markdown("##### Stil", elem_classes="input-label") | |
style_selection = gr.Dropdown(label='Stil', choices=style_keys, value='Kinofilm', container=False) | |
run_button = gr.Button(value="Weihnachtskarte\nerstellen", variant='primary', elem_classes='generate_button') | |
progress_html = gr.HTML(visible=False, elem_id='progress-bar', elem_classes='progress-bar') | |
generated_image = gr.Image(label="Weihnachtskarte", width=1280, value="resources/init.png" ) | |
run_button.click(fn=generate, inputs=[prompt, style_selection], outputs=[run_button, progress_html, generated_image]) | |
shared.gradio_root.queue(concurrency_count=1, api_open=False) | |
shared.gradio_root.launch(server_name="0.0.0.0", show_api=False) | |