aliabd HF staff commited on
Commit
b125efd
1 Parent(s): c8e5654

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ bubble_full_width=False,
31
+ )
32
+
33
+ with gr.Row():
34
+ txt = gr.Textbox(
35
+ scale=4,
36
+ show_label=False,
37
+ placeholder="Enter text and press enter, or upload an image",
38
+ container=False,
39
+ )
40
+ btn = gr.UploadButton("📁", file_types=["image", "video", "audio"])
41
+
42
+ txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
43
+ bot, chatbot, chatbot
44
+ )
45
+ txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
46
+ file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
47
+ bot, chatbot, chatbot
48
+ )
49
+
50
+ demo.queue()
51
+ if __name__ == "__main__":
52
+ demo.launch()