Spaces:
Runtime error
Runtime error
EmicoBinsfinder
commited on
Commit
•
a1bc39d
1
Parent(s):
8e63471
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def add_text(history, text):
|
4 |
+
history = history + [(text, None)]
|
5 |
+
return history, ""
|
6 |
+
|
7 |
+
def add_file(history, file):
|
8 |
+
history = history + [((file.name,), None)]
|
9 |
+
return history
|
10 |
+
|
11 |
+
def bot(history):
|
12 |
+
response = "**That's cool!**"
|
13 |
+
history[-1][1] = response
|
14 |
+
return history
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)
|
18 |
+
|
19 |
+
with gr.Row():
|
20 |
+
with gr.Column(scale=0.85):
|
21 |
+
txt = gr.Textbox(
|
22 |
+
show_label=False,
|
23 |
+
placeholder="Enter text and press enter, or upload an image",
|
24 |
+
).style(container=False)
|
25 |
+
with gr.Column(scale=0.15, min_width=0):
|
26 |
+
btn = gr.UploadButton("📁", file_types=["image", "video", "audio"])
|
27 |
+
|
28 |
+
txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
|
29 |
+
bot, chatbot, chatbot
|
30 |
+
)
|
31 |
+
btn.upload(add_file, [chatbot, btn], [chatbot]).then(
|
32 |
+
bot, chatbot, chatbot
|
33 |
+
)
|
34 |
+
|
35 |
+
demo.launch()
|