aliabd HF staff commited on
Commit
eab22be
β€’
1 Parent(s): 9483b38

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. run.ipynb +1 -1
  3. run.py +10 -5
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: πŸ”₯
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
- sdk_version: 3.32.0
9
  app_file: run.py
10
  pinned: false
11
  ---
 
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 3.33.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(history, text):\n", " history = history + [(text, None)]\n", " return history, \"\"\n", "\n", "def add_file(history, file):\n", " history = history + [((file.name,), None)]\n", " return history\n", "\n", "def bot(history):\n", " response = \"**That's cool!**\"\n", " history[-1][1] = response\n", " return history\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot([], elem_id=\"chatbot\").style(height=750)\n", " \n", " with gr.Row():\n", " with gr.Column(scale=0.85):\n", " txt = gr.Textbox(\n", " show_label=False,\n", " placeholder=\"Enter text and press enter, or upload an image\",\n", " ).style(container=False)\n", " with gr.Column(scale=0.15, min_width=0):\n", " btn = gr.UploadButton(\"\ud83d\udcc1\", file_types=[\"image\", \"video\", \"audio\"])\n", " \n", " txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(\n", " bot, chatbot, chatbot\n", " )\n", " btn.upload(add_file, [chatbot, btn], [chatbot]).then(\n", " bot, chatbot, chatbot\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
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", "\n", "def add_text(history, text):\n", " history = history + [(text, None)]\n", " return history, gr.update(value=\"\", interactive=False)\n", "\n", "\n", "def add_file(history, file):\n", " history = history + [((file.name,), None)]\n", " return history\n", "\n", "\n", "def bot(history):\n", " response = \"**That's cool!**\"\n", " history[-1][1] = response\n", " return history\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot([], elem_id=\"chatbot\").style(height=750)\n", "\n", " with gr.Row():\n", " with gr.Column(scale=0.85):\n", " txt = gr.Textbox(\n", " show_label=False,\n", " placeholder=\"Enter text and press enter, or upload an image\",\n", " ).style(container=False)\n", " with gr.Column(scale=0.15, min_width=0):\n", " btn = gr.UploadButton(\"\ud83d\udcc1\", file_types=[\"image\", \"video\", \"audio\"])\n", "\n", " txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(\n", " bot, chatbot, chatbot\n", " )\n", " txt_msg.then(lambda: gr.update(interactive=True), None, [txt], queue=False)\n", " file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(\n", " bot, chatbot, chatbot\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -1,21 +1,25 @@
1
  import gradio as gr
2
 
 
3
  def add_text(history, text):
4
  history = history + [(text, None)]
5
- return history, ""
 
6
 
7
  def add_file(history, file):
8
  history = history + [((file.name,), None)]
9
  return history
10
 
 
11
  def bot(history):
12
  response = "**That's cool!**"
13
  history[-1][1] = response
14
  return history
15
 
 
16
  with gr.Blocks() as demo:
17
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)
18
-
19
  with gr.Row():
20
  with gr.Column(scale=0.85):
21
  txt = gr.Textbox(
@@ -24,11 +28,12 @@ with gr.Blocks() as demo:
24
  ).style(container=False)
25
  with gr.Column(scale=0.15, min_width=0):
26
  btn = gr.UploadButton("πŸ“", file_types=["image", "video", "audio"])
27
-
28
- txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
29
  bot, chatbot, chatbot
30
  )
31
- btn.upload(add_file, [chatbot, btn], [chatbot]).then(
 
32
  bot, chatbot, chatbot
33
  )
34
 
 
1
  import gradio as gr
2
 
3
+
4
  def add_text(history, text):
5
  history = history + [(text, None)]
6
+ return history, gr.update(value="", interactive=False)
7
+
8
 
9
  def add_file(history, file):
10
  history = history + [((file.name,), None)]
11
  return history
12
 
13
+
14
  def bot(history):
15
  response = "**That's cool!**"
16
  history[-1][1] = response
17
  return history
18
 
19
+
20
  with gr.Blocks() as demo:
21
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=750)
22
+
23
  with gr.Row():
24
  with gr.Column(scale=0.85):
25
  txt = gr.Textbox(
 
28
  ).style(container=False)
29
  with gr.Column(scale=0.15, min_width=0):
30
  btn = gr.UploadButton("πŸ“", file_types=["image", "video", "audio"])
31
+
32
+ txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
33
  bot, chatbot, chatbot
34
  )
35
+ txt_msg.then(lambda: gr.update(interactive=True), None, [txt], queue=False)
36
+ file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
37
  bot, chatbot, chatbot
38
  )
39