Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import plotly.express as px
|
3 |
+
|
4 |
+
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.
|
5 |
+
|
6 |
+
def random_plot():
|
7 |
+
df = px.data.iris()
|
8 |
+
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
|
9 |
+
size='petal_length', hover_data=['petal_width'])
|
10 |
+
return fig
|
11 |
+
|
12 |
+
def print_like_dislike(x: gr.LikeData):
|
13 |
+
print(x.index, x.value, x.liked)
|
14 |
+
|
15 |
+
def add_message(history, message):
|
16 |
+
for x in message["files"]:
|
17 |
+
history.append(((x,), None))
|
18 |
+
if message["text"] is not None:
|
19 |
+
history.append((message["text"], None))
|
20 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
21 |
+
|
22 |
+
def bot(history):
|
23 |
+
history[-1][1] = "Cool!"
|
24 |
+
return history
|
25 |
+
|
26 |
+
fig = random_plot()
|
27 |
+
|
28 |
+
with gr.Blocks(fill_height=True) as demo:
|
29 |
+
chatbot = gr.Chatbot(
|
30 |
+
elem_id="chatbot",
|
31 |
+
bubble_full_width=False,
|
32 |
+
scale=1,
|
33 |
+
)
|
34 |
+
|
35 |
+
chat_input = gr.MultimodalTextbox(interactive=True,
|
36 |
+
file_count="multiple",
|
37 |
+
placeholder="Enter message or upload file...", show_label=False)
|
38 |
+
|
39 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
40 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
41 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
42 |
+
|
43 |
+
chatbot.like(print_like_dislike, None, None)
|
44 |
+
|
45 |
+
demo.launch()
|