import gradio as gr 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 shared.gradio_root = gr.Blocks(title='QualityMinds AI Christmas Card Maker', css=modules.html.css) with shared.gradio_root: gr.Markdown( """ # QualityMinds AI Christmas Card Maker Type a promt and click generate. Try our examples and different styles. """) with gr.Row(elem_classes='type_row'): with gr.Column(scale=0.7): prompt = gr.Textbox(label="Prompt", value="", placeholder="What's on your christmas card?", autofocus=True, elem_classes='type_row', lines=2) with gr.Column(scale=0.15, min_width="120px"): style_selection = gr.Dropdown(label='Style', choices=style_keys, value='Cinematic', elem_classes="stylebox") with gr.Column(scale=0.15, min_width="120px"): run_button = gr.Button(label="Generate", value="Generate", variant='primary', elem_classes='generate_button') progress_html = gr.HTML(visible=False, elem_id='progress-bar', elem_classes='progress-bar') gr.Examples(examples=["Santa Claus with his sack full of gifts", "Scenic winter village inside a snow globe", \ "Cute penguins wrapped up in scarves and hats", "Snowy trees and a reindeer"], inputs=[prompt], cache_examples=False) generated_image = gr.Image(show_label=False, width=1280, value="resources/init.png", show_share_button=True ) 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)