Jether commited on
Commit
4441624
·
verified ·
1 Parent(s): 5bb4979

Update app.py

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