Skip to content
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

Merged
merged 24 commits into from Feb 9, 2024
Merged

Fix gr.load for file-based Spaces #7350

merged 24 commits into from Feb 9, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 8, 2024

There were two separate issues going on:

  1. 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.

  2. 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 if deserialize=False, which is a new parameter in Client (I considered other ways to implement this, including changing the behavior of serialize 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:

import gradio as gr

gr.load("gradio-tests/space_with_files_v4_sse_v2", src="spaces").launch()

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.

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 8, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

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"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 8, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
gradio_client patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix gr.load for file-based Spaces

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs marked this pull request as ready for review February 8, 2024 00:46
@abidlabs abidlabs added the v: minor A change that requires a minor release label Feb 8, 2024
@abidlabs abidlabs removed the v: minor A change that requires a minor release label Feb 8, 2024
Copy link
Collaborator

@freddyaboulton freddyaboulton left a 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,
Copy link
Collaborator

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?

Copy link
Member Author

@abidlabs abidlabs Feb 9, 2024

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)

Copy link
Member Author

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

@abidlabs abidlabs merged commit 7302a6e into main Feb 9, 2024
7 checks passed
@abidlabs abidlabs deleted the gr-load branch February 9, 2024 19:24
@pngwn pngwn mentioned this pull request Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A Space loaded with gr.load() is not functional
3 participants