joaogante HF staff commited on
Commit
2503b95
1 Parent(s): 5c62403
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,7 +1,24 @@
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 gradio as gr
2
+ import random
3
+ import time
4
 
5
+ with gr.Blocks() as demo:
6
+ chatbot = gr.Chatbot()
7
+ msg = gr.Textbox()
8
+ clear = gr.Button("Clear")
9
 
10
+ def user(user_message, history):
11
+ return "", history + [[user_message, None]]
12
+
13
+ def bot(history):
14
+ bot_message = random.choice(["Yes", "No"])
15
+ history[-1][1] = bot_message
16
+ time.sleep(1)
17
+ return history
18
+
19
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
20
+ bot, chatbot, chatbot
21
+ )
22
+ clear.click(lambda: None, None, chatbot, queue=False)
23
+
24
+ demo.launch()