Spaces:
Configuration error
Configuration error
Yurii Paniv
commited on
Commit
•
03ce9f7
1
Parent(s):
58d1e35
Add sample chatbot
Browse files- app.py +26 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
def chat(message, history):
|
6 |
+
history = history or []
|
7 |
+
if message.startswith("How many"):
|
8 |
+
response = random.randint(1, 10)
|
9 |
+
elif message.startswith("How"):
|
10 |
+
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
11 |
+
elif message.startswith("Where"):
|
12 |
+
response = random.choice(["Here", "There", "Somewhere"])
|
13 |
+
else:
|
14 |
+
response = "I don't know"
|
15 |
+
history.append((message, response))
|
16 |
+
return history, history
|
17 |
+
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
chat,
|
21 |
+
["text", "state"],
|
22 |
+
["chatbot", "state"],
|
23 |
+
allow_screenshot=False,
|
24 |
+
allow_flagging="never",
|
25 |
+
)
|
26 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==2.8.2
|
2 |
+
jinja2==3.0.3
|