Spaces:
Running
Running
Upload with huggingface_hub
Browse files
README.md
CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
-
sdk_version: 3.
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 3.20.0
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
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": ["import gradio as gr\n", "\n", "def add_text(
|
|
|
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": ["import gradio as gr\n", "from urllib.parse import quote\n", "\n", "def add_text(history, text):\n", " history = history + [(text, text + \"?\")]\n", " return history\n", "\n", "def add_image(history, image):\n", " history = history + [(f\"![](/file={quote(image.name)})\", \"Cool pic!\")]\n", " return history\n", "\n", "\n", "with gr.Blocks(css=\"#chatbot .overflow-y-auto{height:500px}\") as demo:\n", " chatbot = gr.Chatbot(elem_id=\"chatbot\")\n", " \n", " with gr.Row():\n", " with gr.Column(scale=0.85):\n", " txt = gr.Textbox(show_label=False, placeholder=\"Enter text and press enter, or upload an image\").style(container=False)\n", " with gr.Column(scale=0.15, min_width=0):\n", " btn = gr.UploadButton(\"\ud83d\uddbc\ufe0f\", file_types=[\"image\"])\n", " \n", " txt.submit(add_text, [chatbot, txt], [chatbot])\n", " txt.submit(lambda :\"\", None, txt, queue=False)\n", " btn.upload(add_image, [chatbot, btn], [chatbot])\n", " \n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def add_text(
|
4 |
-
|
5 |
-
return
|
6 |
|
7 |
-
def add_image(
|
8 |
-
|
9 |
-
return
|
10 |
|
11 |
|
12 |
with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
13 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
14 |
-
state = gr.State([])
|
15 |
|
16 |
with gr.Row():
|
17 |
with gr.Column(scale=0.85):
|
@@ -19,9 +19,9 @@ with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
|
19 |
with gr.Column(scale=0.15, min_width=0):
|
20 |
btn = gr.UploadButton("🖼️", file_types=["image"])
|
21 |
|
22 |
-
txt.submit(add_text, [
|
23 |
-
txt.submit(lambda :"", None, txt)
|
24 |
-
btn.upload(add_image, [
|
25 |
|
26 |
if __name__ == "__main__":
|
27 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from urllib.parse import quote
|
3 |
|
4 |
+
def add_text(history, text):
|
5 |
+
history = history + [(text, text + "?")]
|
6 |
+
return history
|
7 |
|
8 |
+
def add_image(history, image):
|
9 |
+
history = history + [(f"![](/file={quote(image.name)})", "Cool pic!")]
|
10 |
+
return history
|
11 |
|
12 |
|
13 |
with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
|
14 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
|
|
15 |
|
16 |
with gr.Row():
|
17 |
with gr.Column(scale=0.85):
|
|
|
19 |
with gr.Column(scale=0.15, min_width=0):
|
20 |
btn = gr.UploadButton("🖼️", file_types=["image"])
|
21 |
|
22 |
+
txt.submit(add_text, [chatbot, txt], [chatbot])
|
23 |
+
txt.submit(lambda :"", None, txt, queue=False)
|
24 |
+
btn.upload(add_image, [chatbot, btn], [chatbot])
|
25 |
|
26 |
if __name__ == "__main__":
|
27 |
demo.launch()
|