Spaces:
Runtime error
Runtime error
Ali Abid
commited on
Commit
Β·
e29f6c4
1
Parent(s):
eb115f5
changes
Browse files
README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
---
|
2 |
title: Chatbot Test
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.24.1
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
---
|
|
|
1 |
---
|
2 |
title: Chatbot Test
|
3 |
+
emoji: π¬
|
4 |
+
colorFrom: blue
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.24.1
|
8 |
+
app_file: run.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
---
|
run.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
response = "That's amazing!"
|
14 |
+
for index, _ in enumerate(response):
|
15 |
+
history[-1][1] = response[:index + 1]
|
16 |
+
time.sleep(0.1)
|
17 |
+
yield history
|
18 |
+
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
chatbot = gr.Chatbot([], elem_id="chatbot")
|
21 |
+
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column(scale=0.85):
|
24 |
+
txt = gr.Textbox(
|
25 |
+
show_label=False,
|
26 |
+
placeholder="Enter text and press enter, or upload an image",
|
27 |
+
).style(container=False)
|
28 |
+
with gr.Column(scale=0.15, min_width=0):
|
29 |
+
btn = gr.UploadButton("π", file_types=["image", "video", "audio"])
|
30 |
+
|
31 |
+
txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
|
32 |
+
bot, chatbot, chatbot
|
33 |
+
)
|
34 |
+
btn.upload(add_file, [chatbot, btn], [chatbot]).then(
|
35 |
+
bot, chatbot, chatbot
|
36 |
+
)
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
demo.queue().launch()
|