From 2b2b50ef9156fa75050f9e65102418dc856737e8 Mon Sep 17 00:00:00 2001 From: lvmin Date: Thu, 10 Aug 2023 14:11:56 -0700 Subject: [PATCH] i --- webui.py | 58 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/webui.py b/webui.py index c22fffc2..edd16765 100644 --- a/webui.py +++ b/webui.py @@ -1,27 +1,47 @@ import gradio as gr +import random +import time -from modules.sdxl_styles import apply_style -from modules.default_pipeline import process +# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text. + +def add_text(history, text): + history = history + [(text, None)] + return history, gr.update(value="", interactive=False) -def generate_clicked(positive_prompt): - - p, n = apply_style('sai-cinematic', positive_prompt, '') - - print(p) - print(n) - - return process(positive_prompt=p, - negative_prompt=n) +def add_file(history, file): + history = history + [((file.name,), None)] + return history -block = gr.Blocks().queue() -with block: - with gr.Column(): - prompt = gr.Textbox(label="Prompt", value='a handsome man in forest') - run_button = gr.Button(label="Run") - result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", height=1280) - run_button.click(fn=generate_clicked, inputs=[prompt], outputs=[result_gallery]) +def bot(history): + response = "**That's cool!**" + history[-1][1] = "" + for character in response: + history[-1][1] += character + time.sleep(0.05) + yield history -block.launch() +with gr.Blocks() as demo: + chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750) + + with gr.Row(): + with gr.Column(scale=0.85): + txt = gr.Textbox( + show_label=False, + placeholder="Enter text and press enter, or upload an image", + ).style(container=False) + with gr.Column(scale=0.15, min_width=0): + btn = gr.UploadButton("📁", file_types=["image", "video", "audio"]) + + txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then( + bot, chatbot, chatbot + ) + txt_msg.then(lambda: gr.update(interactive=True), None, [txt], queue=False) + file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then( + bot, chatbot, chatbot + ) + +demo.queue() +demo.launch()