ysharma HF Staff commited on
Commit
e43ab45
·
verified ·
1 Parent(s): 28510ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ with gr.Blocks() as demo:
27
+ chatbot = gr.Chatbot(
28
+ [],
29
+ elem_id="chatbot",
30
+ bubble_full_width=False
31
+ )
32
+
33
+ chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)
34
+
35
+ chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
36
+ bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
37
+ bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
38
+
39
+ chatbot.like(print_like_dislike, None, None)
40
+
41
+ demo.queue()
42
+ if __name__ == "__main__":
43
+ demo.launch()