Replay text-encoded files in gr.load_chat history as text, not as images - #13743
Closed
abidlabs wants to merge 1 commit into
Closed
Replay text-encoded files in gr.load_chat history as text, not as images#13743abidlabs wants to merge 1 commit into
gr.load_chat history as text, not as images#13743abidlabs wants to merge 1 commit into
Conversation
`format_conversation()` inlines a text-encoded file into the prompt on the turn
it is sent, but turned every `file` content part in the *history* into
`{"type": "image_url", ...}` regardless of its type. So the turn where a large
pasted prompt became a .txt attachment worked, and every message after it sent
that .txt back base64-encoded as an image -- which is why the reporter's next
short message failed with "model is not multimodal" on `vllm serve`.
Text-encoded files in the history are now inlined as text the same way they are
when first sent; images still go out as `image_url`.
Fixes #11331
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Collaborator
🪼 branch checks and previews
Install Gradio from this PR pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/607eb88ee96c9fff301565e0a2b01688bac13aaf/gradio-6.23.1-py3-none-any.whlInstall Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@607eb88ee96c9fff301565e0a2b01688bac13aaf#subdirectory=client/python"Import Gradio JS Client from this PR via CDN import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/607eb88ee96c9fff301565e0a2b01688bac13aaf/browser.js"; |
Collaborator
🦄 change detectedThis Pull Request includes changes to the following packages.
|
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11331
Root cause
With the default
gr.load_chat(..., file_types="text_encoded"), pasting a large prompt turns it into a text-file attachment.format_conversation()handles that correctly on the turn it is sent — it reads text-encoded files and appends their contents to the prompt as text.But when it walks the history, it turned every
filecontent part into an image regardless of type:So the pasted-text turn goes out fine, and then every message after it re-sends that
.txtbase64-encoded as an image — the payload literally contains"url": "data:text/plain;base64,...". That is the requestvllm serverejects with "model is not multimodal", which matches the reported sequence exactly: paste long text (works) → type something short (fails).It also explains why
file_types=[]made the error go away: no attachment, so nothing to replay.Fix
Text-encoded files in the history are inlined as text, the same as when they were first sent. Images still go out as
image_url. The extension check and the## filename\ncontentsformatting are now shared between the two paths so they cannot drift again, and the check also excludes http(s) URLs, whichPath(...).read_text()could not have handled anyway.Verification
test_format_conversation_replays_text_files_as_textis new and fails onmain:It also pins that a
.pngin the history is still sent asimage_url. Fulltest/test_external.py: the 3 pre-existing failures are unchanged (test_load_chat_*, which needopenai, not installed in my env).TestLoadInterface::test_multiple_spaces_one_privateflaked in one batch run and passes on its own — it hits real Spaces over the network.End-to-end, with the demo below (a local stand-in for
vllm servethat rejects image content the way a non-multimodal model does):Minimal demo (not committed)
The full demo file (which also starts a fake OpenAI-compatible server and drives a real
gr.load_chat) was kept untracked and is not part of this PR.🤖 Generated with Claude Code