GreenRaptor commited on
Commit
98b5314
·
1 Parent(s): 7ab8364

initial commit

Browse files
Files changed (1) hide show
  1. app.py +18 -26
app.py CHANGED
@@ -1,35 +1,27 @@
1
  import gradio as gr
2
-
3
- def add_text(history, text):
4
- history = history + [(text, None)]
5
- return history, ""
6
-
7
- def add_file(history, file):
8
- history = history + [((file.name,), None)]
9
- return history
10
-
11
- def bot(history):
12
- response = "That's cool!"
13
- history[-1][1] = response
14
- return history
15
 
16
  with gr.Blocks() as demo:
17
- chatbot = gr.Chatbot([], elem_id="chatbot").style(height=500)
 
 
18
 
19
- with gr.Row():
20
- with gr.Column(scale=0.85):
21
- txt = gr.Textbox(
22
- show_label=False,
23
- placeholder="Type your response and press enter, or record your response",
24
- ).style(container=False)
25
- with gr.Column(scale=0.15, min_width=0):
26
- btn = gr.UploadButton("Submit", file_types=["text"])
27
 
28
- txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
29
- bot, chatbot, chatbot
30
- )
31
- btn.upload(add_file, [chatbot, btn], [chatbot]).then(
 
 
 
 
 
32
  bot, chatbot, chatbot
33
  )
 
34
 
 
35
  demo.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()
27
  demo.launch()