nugentc commited on
Commit
703a8b7
·
1 Parent(s): 12b21b0

add a chatbot interface

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,7 +1,27 @@
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()