tongxiaojun commited on
Commit
923b2fa
·
1 Parent(s): 530e836

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -1,18 +1,28 @@
1
  import gradio as gr
2
- import requests
3
- from PIL import Image
4
- URL = "https://source.unsplash.com/random/500x500/?nature,fruit"
5
 
 
 
 
 
6
 
7
- def refresh():
8
- image = Image.open(requests.get(URL, stream=True).raw)
9
- return image
10
 
 
 
 
 
 
 
 
11
 
12
- with gr.Blocks(show_footer=False) as blocks:
13
- image = gr.Image(show_label=False)
14
- blocks.load(fn=refresh, inputs=None, outputs=image,
15
- show_progress=False, every=1)
16
-
17
- blocks.queue(api_open=False)
18
- blocks.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(["How are you?", "I love you", "I'm very hungry"])
15
+ history[-1][1] = ""
16
+ for character in bot_message:
17
+ history[-1][1] += character
18
+ time.sleep(0.05)
19
+ yield history
20
 
21
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
22
+ bot, chatbot, chatbot
23
+ )
24
+ clear.click(lambda: None, None, chatbot, queue=False)
25
+
26
+ demo.queue(api_open=False)
27
+ if __name__ == "__main__":
28
+ demo.launch()