diff --git a/.changeset/legal-aliens-burn.md b/.changeset/legal-aliens-burn.md new file mode 100644 index 0000000000000..e2c391c730c8e --- /dev/null +++ b/.changeset/legal-aliens-burn.md @@ -0,0 +1,6 @@ +--- +"@gradio/chatbot": minor +"gradio": minor +--- + +feat:Allow Chatbot examples to show more than one image diff --git a/gradio/chat_interface.py b/gradio/chat_interface.py index 0333a49d4e1a3..c3a05f67a7f82 100644 --- a/gradio/chat_interface.py +++ b/gradio/chat_interface.py @@ -319,8 +319,8 @@ def __init__( self._setup_events() self._setup_api() - @staticmethod def _setup_example_messages( + self, examples: list[str] | list[MultimodalValue] | list[list] | None, example_labels: list[str] | None = None, example_icons: list[str] | None = None, @@ -338,8 +338,21 @@ def _setup_example_messages( example_message["files"] = example.get("files", []) if example_labels: example_message["display_text"] = example_labels[index] - if example_icons: - example_message["icon"] = example_icons[index] + if self.multimodal: + example_files = example_message.get("files") + if not example_files: + if example_icons: + example_message["icon"] = example_icons[index] + else: + example_message["icon"] = { + "path": "", + "url": None, + "orig_name": None, + "mime_type": "text", # for internal use, not a valid mime type + "meta": {"_type": "gradio.FileData"}, + } + elif example_icons: + example_message["icon"] = example_icons[index] examples_messages.append(example_message) return examples_messages diff --git a/js/chatbot/Chatbot.stories.svelte b/js/chatbot/Chatbot.stories.svelte index c968da32e5fff..4649eaed97708 100644 --- a/js/chatbot/Chatbot.stories.svelte +++ b/js/chatbot/Chatbot.stories.svelte @@ -223,3 +223,138 @@ This document is a showcase of various Markdown capabilities.`, ] }} /> + + + + diff --git a/js/chatbot/shared/ChatBot.svelte b/js/chatbot/shared/ChatBot.svelte index 99b5a723cb5bd..36dea51c02897 100644 --- a/js/chatbot/shared/ChatBot.svelte +++ b/js/chatbot/shared/ChatBot.svelte @@ -34,6 +34,8 @@ import { ShareError } from "@gradio/utils"; import { Gradio } from "@gradio/utils"; + import Examples from "./Examples.svelte"; + export let value: NormalisedMessage[] | null = []; let old_value: NormalisedMessage[] | null = null; @@ -328,55 +330,13 @@ {/if} {:else} -
- {#if placeholder !== null} -
- -
- {/if} - {#if examples !== null} -
- {#each examples as example, i} - - {/each} -
- {/if} -
+ dispatch("example_select", e.detail)} + /> {/if} @@ -392,93 +352,6 @@ {/if} diff --git a/js/spa/test/test_chatinterface_multimodal_examples.spec.ts b/js/spa/test/test_chatinterface_multimodal_examples.spec.ts index 7cf87d592107e..7025f88b60bdf 100644 --- a/js/spa/test/test_chatinterface_multimodal_examples.spec.ts +++ b/js/spa/test/test_chatinterface_multimodal_examples.spec.ts @@ -20,7 +20,7 @@ for (const test_case of cases) { // Clear the chat and click on a different example, the input/response are correct await page.getByLabel("Clear").click(); - await page.getByRole("button", { name: "hola example-image" }).click(); + await page.getByRole("button", { name: "Select example 2: hola" }).click(); await expect(page.locator(".user img")).toBeVisible(); await expect(page.locator(".user p")).toContainText("hola"); await expect(page.locator(".bot p")).toContainText(