New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix gr.load
for file-based Spaces
#7350
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/fa3d844abf06eabc283de322b13161c651b120ac/gradio-4.17.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@fa3d844abf06eabc283de322b13161c651b120ac#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice clean up and fix @abidlabs !
@@ -77,20 +77,23 @@ def __init__( | |||
auth: tuple[str, str] | None = None, | |||
*, | |||
headers: dict[str, str] | None = None, | |||
deserialize: bool = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this download_files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree that's a more intuitive name. I'll rename serialize to download_files as well (and soft-deprecate serialize)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change @freddyaboulton, will merge in after CI
There were two separate issues going on:
We weren't handling URLs correctly in the Client. In particular, we would transform any string that was a valid URL to a dictionary consisting of a path regardless of whether the value corresponded to a file-based component. Now, we check to see if the component is a file-based component. This is still not totally robust, as we should actually inspect the typing information to see which part of the payload is actually the file, but getting that working is a bit tricky. For now, this should be a good enough solution and I've created a new issue to track. To skip conversion, one can still set
serialize=False
.When we loaded a Space using
gr.load()
and that Space had output files, we were unnecessarily copying them locally and serving the local files. This is not only inefficient but also doesn't work well with some components after the normalize_files refactor. Now we simply serve the files directly from the remote Space using the/proxy
route ifdeserialize=False
, which is a new parameter inClient
(I considered other ways to implement this, including changing the behavior ofserialize
to cover this, but all led to other side effects or breaking changes).Closes: #6744
The original Space doesn't have a repro but you can try this:
I also tested this with a private version of the same Space, but it'd be great to test with a few other Spaces to make sure
gr.load()
is working as expected.