jdoexbox360 commited on
Commit
c2ec55a
·
1 Parent(s): c487695

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+
4
+ def add_text(history, text):
5
+ history = history + [(text, None)]
6
+ return history, ""
7
+
8
+ def add_file(history, file):
9
+ history = history + [((file.name,), None)]
10
+ return history
11
+
12
+ def bot(history):
13
+ last = history[-1][0]
14
+ response = last[::-1]
15
+
16
+ history[-1][1] = response
17
+ return history
18
+ # for index, _ in enumerate(response):
19
+ # history[-1][1] = response[:index + 1]
20
+ # time.sleep(0.1)
21
+ # yield history
22
+
23
+ with gr.Blocks() as demo:
24
+ chatbot = gr.Chatbot([], elem_id="chatbot")
25
+
26
+ with gr.Row():
27
+ with gr.Column(scale=0.85):
28
+ txt = gr.Textbox(
29
+ show_label=False,
30
+ placeholder="Enter text and press enter, or upload an image",
31
+ ).style(container=False)
32
+ with gr.Column(scale=0.15, min_width=0):
33
+ btn = gr.UploadButton("📁", file_types=["image", "video", "audio"])
34
+
35
+ txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
36
+ bot, chatbot, chatbot
37
+ )
38
+ btn.upload(add_file, [chatbot, btn], [chatbot]).then(
39
+ bot, chatbot, chatbot
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ demo.queue().launch()