From 6b854eefd40797494598af13e5fb0b44b2be000e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ty=C3=A9=20singwa?= <92231658+tye-singwa@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:45:04 +0300 Subject: [PATCH] Allow image url as ChatBot response (#3953) * fix(chatbot): allow url as chatbot response * chore(changelog): update changelog * fix: update per review Co-authored-by: Abubakar Abid --------- Co-authored-by: Abubakar Abid --- CHANGELOG.md | 1 + gradio/components.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f51ac0440..7da2435754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ No changes to highlight. - Fix issue where requesting for a non-existing file would trigger a 500 error by [@micky2be](https://github.com/micky2be) in `[PR 3895](https://github.com/gradio-app/gradio/pull/3895)`. - Fix bugs with abspath about symlinks, and unresolvable path on Windows by [@micky2be](https://github.com/micky2be) in `[PR 3895](https://github.com/gradio-app/gradio/pull/3895)`. - Fixes type in client `Status` enum by [@10zinten](https://github.com/10zinten) in [PR 3931](https://github.com/gradio-app/gradio/pull/3931) +- Fix `gr.ChatBot` to handle image url [tye-singwa](https://github.com/tye-signwa) in [PR 3953](https://github.com/gradio-app/gradio/pull/3953) ## Documentation Changes: diff --git a/gradio/components.py b/gradio/components.py index 6e8c88a05a..42c892fc31 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -4581,9 +4581,13 @@ class Chatbot(Changeable, Selectable, IOComponent, JSONSerializable): if chat_message is None: return None elif isinstance(chat_message, (tuple, list)): - filepath = chat_message[0] + file_uri = chat_message[0] + if utils.validate_url(file_uri): + filepath = file_uri + else: + filepath = self.make_temp_copy_if_needed(file_uri) + mime_type = client_utils.get_mimetype(filepath) - filepath = self.make_temp_copy_if_needed(filepath) return { "name": filepath, "mime_type": mime_type,