aliabd HF staff commited on
Commit
e3c695c
1 Parent(s): 0915eca

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +6 -7
  2. run.ipynb +1 -0
  3. run.py +27 -0
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Chatbot Multimodal
3
- emoji: 👀
4
- colorFrom: yellow
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 3.12.0
8
- app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: chatbot_multimodal
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.12.0
9
+ app_file: run.py
10
  pinned: false
11
  ---
 
 
run.ipynb ADDED
@@ -0,0 +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(state, text):\n", " state = state + [(text, text + \"?\")]\n", " return state, state\n", "\n", "def add_image(state, image):\n", " state = state + [(f\"![](/file={image.name})\", \"Cool pic!\")]\n", " return state, state\n", "\n", "\n", "with gr.Blocks(css=\"#chatbot .overflow-y-auto{height:500px}\") as demo:\n", " chatbot = gr.Chatbot(elem_id=\"chatbot\")\n", " state = gr.State([])\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, [state, txt], [state, chatbot])\n", " txt.submit(lambda :\"\", None, txt)\n", " btn.upload(add_image, [state, btn], [state, chatbot])\n", " \n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def add_text(state, text):
4
+ state = state + [(text, text + "?")]
5
+ return state, state
6
+
7
+ def add_image(state, image):
8
+ state = state + [(f"![](/file={image.name})", "Cool pic!")]
9
+ return state, state
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):
18
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter, or upload an image").style(container=False)
19
+ with gr.Column(scale=0.15, min_width=0):
20
+ btn = gr.UploadButton("🖼️", file_types=["image"])
21
+
22
+ txt.submit(add_text, [state, txt], [state, chatbot])
23
+ txt.submit(lambda :"", None, txt)
24
+ btn.upload(add_image, [state, btn], [state, chatbot])
25
+
26
+ if __name__ == "__main__":
27
+ demo.launch()