deepakaiplanet commited on
Commit
2b63d60
1 Parent(s): e35e375

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +12 -35
run.py CHANGED
@@ -1,44 +1,21 @@
1
  import gradio as gr
2
- import os
3
  import time
4
 
5
- # Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
6
-
7
-
8
- def print_like_dislike(x: gr.LikeData):
9
- print(x.index, x.value, x.liked)
10
-
11
- def add_message(history, message):
12
- for x in message["files"]:
13
- history.append(((x,), None))
14
- if message["text"] is not None:
15
- history.append((message["text"], None))
16
- return history
17
-
18
- def bot(history):
19
- response = "**That's cool!**"
20
- history[-1][1] = "asasa"
21
- for character in response:
22
- history[-1][1] += character
23
- time.sleep(0.05)
24
- yield history
25
-
26
-
27
  with gr.Blocks() as demo:
28
- chatbot = gr.Chatbot(
29
- [],
30
- elem_id="chatbot",
31
- bubble_full_width=False,
32
- )
33
 
34
- chat_input = gr.Textbox(interactive=True, placeholder="Enter message or upload file...", show_label=False)
 
 
 
 
35
 
36
- chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
37
- bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
38
- bot_msg.then(None, [chat_input])
39
 
40
- chatbot.like(print_like_dislike, None, None)
41
-
42
- demo.queue()
43
  if __name__ == "__main__":
44
  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.ClearButton([msg, chatbot])
 
 
9
 
10
+ def respond(message, chat_history):
11
+ bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
12
+ chat_history.append((message, bot_message))
13
+ time.sleep(2)
14
+ return "", chat_history
15
 
16
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
 
17
 
 
 
 
18
  if __name__ == "__main__":
19
  demo.launch()
20
+
21
+