This commit is contained in:
lvmin 2023-08-10 14:11:56 -07:00
parent 3516fb2d85
commit 2b2b50ef91

View File

@ -1,27 +1,47 @@
import gradio as gr import gradio as gr
import random
import time
from modules.sdxl_styles import apply_style # Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
from modules.default_pipeline import process
def add_text(history, text):
history = history + [(text, None)]
return history, gr.update(value="", interactive=False)
def generate_clicked(positive_prompt): def add_file(history, file):
history = history + [((file.name,), None)]
p, n = apply_style('sai-cinematic', positive_prompt, '') return history
print(p)
print(n)
return process(positive_prompt=p,
negative_prompt=n)
block = gr.Blocks().queue() def bot(history):
with block: response = "**That's cool!**"
with gr.Column(): history[-1][1] = ""
prompt = gr.Textbox(label="Prompt", value='a handsome man in forest') for character in response:
run_button = gr.Button(label="Run") history[-1][1] += character
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", height=1280) time.sleep(0.05)
run_button.click(fn=generate_clicked, inputs=[prompt], outputs=[result_gallery]) 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()