ysharma HF Staff commited on
Commit
c25db33
·
verified ·
1 Parent(s): af3c6dd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, gr.MultimodalTextbox(value=None, interactive=False)
17
+
18
+ def bot(history):
19
+ response = "**That's cool!**"
20
+ history[-1][1] = ""
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.MultimodalTextbox(interactive=True, file_types=["image"], 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(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
39
+
40
+ chatbot.like(print_like_dislike, None, None)
41
+
42
+ demo.queue()
43
+ if __name__ == "__main__":
44
+ demo.launch()
45
+
46
+