Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +1 -1
- files/avatar.png +0 -0
- files/lion.jpg +0 -0
- run.ipynb +1 -1
- run.py +10 -27
README.md
CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
-
sdk_version: 4.
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 4.22.0
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
files/avatar.png
ADDED
files/lion.jpg
ADDED
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_multimodal"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/chatbot_multimodal/avatar.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "import time\n", "\n", "# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.\n", "\n", "\n", "def print_like_dislike(x: gr.LikeData):\n", " print(x.index, x.value, x.liked)\n", "\n", "
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_multimodal"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('files')\n", "!wget -q -O files/avatar.png https://github.com/gradio-app/gradio/raw/main/demo/chatbot_multimodal/files/avatar.png\n", "!wget -q -O files/lion.jpg https://github.com/gradio-app/gradio/raw/main/demo/chatbot_multimodal/files/lion.jpg"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import os\n", "import time\n", "\n", "# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, & video). Plus shows support for streaming text.\n", "\n", "\n", "def print_like_dislike(x: gr.LikeData):\n", " print(x.index, x.value, x.liked)\n", "\n", "def add_message(history, message):\n", " for x in message[\"files\"]:\n", " history.append(((x[\"path\"],), None)) \n", " if message[\"text\"] is not None:\n", " history.append((message[\"text\"], None))\n", " return history, gr.MultimodalTextbox(value=None, interactive=False, file_types=[\"image\"])\n", "\n", "def bot(history):\n", " response = \"**That's cool!**\"\n", " history[-1][1] = \"\"\n", " for character in response:\n", " history[-1][1] += character\n", " time.sleep(0.05)\n", " yield history\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(\n", " [],\n", " elem_id=\"chatbot\",\n", " bubble_full_width=False,\n", " avatar_images=(None, (os.path.join(os.path.abspath(''), \"files/avatar.png\"))),\n", " )\n", "\n", " chat_input = gr.MultimodalTextbox(interactive=True, file_types=[\"image\"], placeholder=\"Enter message or upload file...\", show_label=False)\n", " chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], queue=False).then(\n", " bot, chatbot, chatbot, api_name=\"bot_response\"\n", " )\n", " chat_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input], queue=False)\n", " chatbot.like(print_like_dislike, None, None)\n", "\n", "demo.queue()\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -8,16 +8,12 @@ import time
|
|
8 |
def print_like_dislike(x: gr.LikeData):
|
9 |
print(x.index, x.value, x.liked)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
def add_file(history, file):
|
18 |
-
history = history + [((file.name,), None)]
|
19 |
-
return history
|
20 |
-
|
21 |
|
22 |
def bot(history):
|
23 |
response = "**That's cool!**"
|
@@ -33,29 +29,16 @@ with gr.Blocks() as demo:
|
|
33 |
[],
|
34 |
elem_id="chatbot",
|
35 |
bubble_full_width=False,
|
36 |
-
avatar_images=(None, (os.path.join(os.path.dirname(__file__), "avatar.png"))),
|
37 |
)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
scale=4,
|
42 |
-
show_label=False,
|
43 |
-
placeholder="Enter text and press enter, or upload an image",
|
44 |
-
container=False,
|
45 |
-
)
|
46 |
-
btn = gr.UploadButton("📁", file_types=["image", "video", "audio"])
|
47 |
-
|
48 |
-
txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
49 |
bot, chatbot, chatbot, api_name="bot_response"
|
50 |
)
|
51 |
-
|
52 |
-
file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
|
53 |
-
bot, chatbot, chatbot
|
54 |
-
)
|
55 |
-
|
56 |
chatbot.like(print_like_dislike, None, None)
|
57 |
|
58 |
-
|
59 |
demo.queue()
|
60 |
if __name__ == "__main__":
|
61 |
demo.launch()
|
|
|
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["path"],), None))
|
14 |
+
if message["text"] is not None:
|
15 |
+
history.append((message["text"], None))
|
16 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False, file_types=["image"])
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def bot(history):
|
19 |
response = "**That's cool!**"
|
|
|
29 |
[],
|
30 |
elem_id="chatbot",
|
31 |
bubble_full_width=False,
|
32 |
+
avatar_images=(None, (os.path.join(os.path.dirname(__file__), "files/avatar.png"))),
|
33 |
)
|
34 |
|
35 |
+
chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)
|
36 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], queue=False).then(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
bot, chatbot, chatbot, api_name="bot_response"
|
38 |
)
|
39 |
+
chat_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input], queue=False)
|
|
|
|
|
|
|
|
|
40 |
chatbot.like(print_like_dislike, None, None)
|
41 |
|
|
|
42 |
demo.queue()
|
43 |
if __name__ == "__main__":
|
44 |
demo.launch()
|