Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import time
4
+
5
+ # Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
6
+
7
+
8
+ def add_text(history, text):
9
+ history = history + [(text, None)]
10
+ return history, gr.Textbox(value="", interactive=False)
11
+
12
+
13
+ def add_file(history, file):
14
+ history = history + [((file.name,), None)]
15
+ return history
16
+
17
+
18
+ def bot(history):
19
+ response = "**That's cool!**"
20
+ history[-1][1] = ""
21
+ for character in response:
22
+ history[-1][1] += character
23
+ time.sleep(0.05)
24
+ yield history
25
+
26
+
27
+ with gr.Blocks() as demo:
28
+ chatbot = gr.Chatbot(
29
+ [],
30
+ elem_id="chatbot",
31
+ bubble_full_width=False,
32
+ avatar_images=(None, (os.path.join(os.path.dirname(__file__), "avatar.png"))),
33
+ )
34
+
35
+ with gr.Row():
36
+ txt = gr.Textbox(
37
+ scale=4,
38
+ show_label=False,
39
+ placeholder="Enter text and press enter, or upload an image",
40
+ container=False,
41
+ )
42
+ btn = gr.UploadButton("πŸ“", file_types=["image", "video", "audio"])
43
+
44
+ txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
45
+ bot, chatbot, chatbot
46
+ )
47
+ txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
48
+ file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
49
+ bot, chatbot, chatbot
50
+ )
51
+
52
+ demo.queue()
53
+ if __name__ == "__main__":
54
+ demo.launch()
55
+