gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
29.49k stars 2.19k forks source link

rework upload to be a class method + pass client into each component #8179

Closed pngwn closed 2 weeks ago

pngwn commented 2 weeks ago

Description

Closes #8150.

This PR reworks the upload function exported from @gradio/client to instead be an instance method of the client. This means we do not need to pass the upload_fn in and can instead use this.upload_files which uses this.fetch_implementation. This simplifies things significantly as the lite client and core client define their own fetch and stream methods.

To further reduce the complexity of the code base, i decide to pass the client into each component on the gradio namespace. This allows components to fetch/ stream as needed using the client methods (which are set appropriately for their environment) without us needing to pass individual function using svelte's context.

Wherever an upload function is required, the component can simply call it or pass it down.

gradio-pr-bot commented 2 weeks ago

🪼 branch checks and previews

• Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
:unicorn: Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/a20e4c4ddca976b10afc450e425e6c3bea8ebaaf/gradio-4.28.3-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@a20e4c4ddca976b10afc450e425e6c3bea8ebaaf#subdirectory=client/python"
gradio-pr-bot commented 2 weeks ago

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/app patch
@gradio/audio patch
@gradio/client patch
@gradio/dataframe patch
@gradio/file patch
@gradio/gallery patch
@gradio/image patch
@gradio/imageeditor patch
@gradio/model3d patch
@gradio/multimodaltextbox patch
@gradio/simpleimage patch
@gradio/storybook patch
@gradio/tootils patch
@gradio/upload patch
@gradio/uploadbutton patch
@gradio/utils patch
@gradio/video patch
gradio patch

With the following changelog entry.

rework upload to be a class method + pass client into each component

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](https://github.com/gradio-app/gradio/edit/89150-upload-files/.changeset/huge-rivers-cough.md).
pngwn commented 2 weeks ago

storybook should be fine now.

hannahblair commented 2 weeks ago

There's an issue with the Trim Video snapshot in storybook which is specific to this PR; at first glance I can't see why this would cause it but I can delve into it tmo. Otherwise, looks good - thanks for making the upload logic a lot cleaner! Also, the comments really helped :-)

edit: no worries the trim video snapshot is just a red herring