Skip to content

Commit

Permalink
adds a run_examples_on_click parameter to gr.ChatInterface mirror…
Browse files Browse the repository at this point in the history
…ing the the `run_on_click` parameter in `gr.Examples` (#10109)

* add param

* add changeset

* add changeset

* more changes

* add changeset

* slight refactor

* add changeset

* fix

* fixes

* tweak

* clean

* clean

* lint

* upload

* notebook

* more testing

* changes

* notebook

* add changeset

* notebooks

* format

* format

* fix undo

* changes

* changes

* fix

* changes

* fix assert

---------

Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
abidlabs and gradio-pr-bot authored Dec 7, 2024
1 parent 6645518 commit 48e4aa9
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 123 deletions.
6 changes: 6 additions & 0 deletions .changeset/evil-hoops-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gradio": minor
"website": minor
---

feat:adds a `run_examples_on_click` parameter to `gr.ChatInterface` mirroring the the `run_on_click` parameter in `gr.Examples`
1 change: 0 additions & 1 deletion demo/chatinterface_multimodal/run.ipynb

This file was deleted.

13 changes: 0 additions & 13 deletions demo/chatinterface_multimodal/run.py

This file was deleted.

19 changes: 19 additions & 0 deletions demo/test_chatinterface_multimodal_examples/cached_testcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
import gradio as gr

image = str(Path(__file__).parent / "files" / "avatar.png")
audio = str(Path(__file__).parent / "files" / "cantina.wav")

def echo(message, history):
return f"You wrote: {message['text']} and uploaded {len(message['files'])} files."

demo = gr.ChatInterface(
fn=echo,
type="messages",
examples=[{"text": "hello"}, {"text": "hola", "files": [image]}, {"text": "merhaba", "files": [image, audio]}],
title="Echo Bot",
multimodal=True,
)

if __name__ == "__main__":
demo.launch()
1 change: 1 addition & 0 deletions demo/test_chatinterface_multimodal_examples/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: test_chatinterface_multimodal_examples"]}, {"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/test_chatinterface_multimodal_examples/cached_testcase.py\n", "os.mkdir('files')\n", "!wget -q -O files/avatar.png https://github.com/gradio-app/gradio/raw/main/demo/test_chatinterface_multimodal_examples/files/avatar.png\n", "!wget -q -O files/cantina.wav https://github.com/gradio-app/gradio/raw/main/demo/test_chatinterface_multimodal_examples/files/cantina.wav"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["from pathlib import Path\n", "import gradio as gr\n", "\n", "image = str(Path(__file__).parent / \"files\" / \"avatar.png\")\n", "audio = str(Path(__file__).parent / \"files\" / \"cantina.wav\")\n", "\n", "def echo(message, history):\n", " return f\"You wrote: {message['text']} and uploaded {len(message['files'])} files.\"\n", "\n", "demo = gr.ChatInterface(\n", " fn=echo,\n", " type=\"messages\",\n", " examples=[{\"text\": \"hello\"}, {\"text\": \"hola\", \"files\": [image]}, {\"text\": \"merhaba\", \"files\": [image, audio]}],\n", " title=\"Echo Bot\",\n", " multimodal=True,\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
19 changes: 19 additions & 0 deletions demo/test_chatinterface_multimodal_examples/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path
import gradio as gr

image = str(Path(__file__).parent / "files" / "avatar.png")
audio = str(Path(__file__).parent / "files" / "cantina.wav")

def echo(message, history):
return f"You wrote: {message['text']} and uploaded {len(message['files'])} files."

demo = gr.ChatInterface(
fn=echo,
type="messages",
examples=[{"text": "hello"}, {"text": "hola", "files": [image]}, {"text": "merhaba", "files": [image, audio]}],
title="Echo Bot",
multimodal=True,
)

if __name__ == "__main__":
demo.launch()
Loading

0 comments on commit 48e4aa9

Please sign in to comment.