Spaces:
Build error
Build error
add a chatbot interface
Browse files
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def chat(message, history):
|
| 7 |
+
history = history or []
|
| 8 |
+
if message.startswith("How many"):
|
| 9 |
+
response = random.randint(1, 10)
|
| 10 |
+
elif message.startswith("How"):
|
| 11 |
+
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
| 12 |
+
elif message.startswith("Where"):
|
| 13 |
+
response = random.choice(["Here", "There", "Somewhere"])
|
| 14 |
+
else:
|
| 15 |
+
response = "I don't know"
|
| 16 |
+
history.append((message, response))
|
| 17 |
+
return history, history
|
| 18 |
+
|
| 19 |
+
chatbot = gr.Chatbot(color_map=("green", "gray"))
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
chat,
|
| 22 |
+
["text", "state"],
|
| 23 |
+
[chatbot, "state"],
|
| 24 |
+
allow_screenshot=False,
|
| 25 |
+
allow_flagging="never",
|
| 26 |
+
)
|
| 27 |
+
demo.launch()
|