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

Add an explicit dependency of urllib3~=2.0 and update processing_utils.save_url_to_cache to use urllib3 for Lite support #8011

Merged
merged 9 commits into from Apr 14, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Apr 12, 2024

Description

Closes: #6837

  • Update processing_utils.save_url_to_cache() to use urllib3 to work on Lite as well.
  • To use urllib3, add it in requirements.txt explicitly.
    • Found that the version spec (e.g. >=2.2.0) was not necessary because Pyodide ships urllib==2.1.0 which works on Pyodide and urllib>=2.2.0 supports Pyodide on its end.
    • Moreover, version spec can cause version conflicts like this, so omitting it may be better anyway.

With this PR, apps like below can work that uses examples with URLs.

import gradio as gr


demo = gr.Interface(
	fn=lambda x: x,
	inputs="image",
	outputs="image",
	examples=[
		["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg"],
	]
)


if __name__ == "__main__":
    demo.queue().launch()

…save_url_to_cache` to use `urllib3` for Lite support
@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 12, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/3b1dfba9c550749e913dff57799d31a57556fb32/gradio-4.26.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3b1dfba9c550749e913dff57799d31a57556fb32#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Apr 12, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Add an explicit dependency of urllib3~=2.0 and update processing_utils.save_url_to_cache to use urllib3 for Lite support

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.

@whitphx whitphx added the gradio-lite Related to the @gradio/lite library label Apr 12, 2024
requirements.txt Outdated Show resolved Hide resolved
Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, everything works great! Should be good to merge @whitphx pending the suggestion above

whitphx and others added 2 commits April 14, 2024 17:38
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
@abidlabs abidlabs added the v: minor A change that requires a minor release label Apr 14, 2024
@abidlabs abidlabs changed the title Add an explicit dependency of urllib3 and update processing_utils.save_url_to_cache to use urllib3 for Lite support Add an explicit dependency of urllib3>=2.0 and update processing_utils.save_url_to_cache to use urllib3 for Lite support Apr 14, 2024
@abidlabs
Copy link
Member

Going to upgrade this to a minor since we are updating our requirements. We have a test that is failing b/c botocore does not support urllib 2 but I'm going to see if we can upgrade the version of botocore to fix this

@abidlabs abidlabs changed the title Add an explicit dependency of urllib3>=2.0 and update processing_utils.save_url_to_cache to use urllib3 for Lite support Add an explicit dependency of urllib3~=2.0 and update processing_utils.save_url_to_cache to use urllib3 for Lite support Apr 14, 2024
@abidlabs abidlabs enabled auto-merge (squash) April 14, 2024 17:37
@abidlabs abidlabs merged commit f17d1a0 into main Apr 14, 2024
7 checks passed
@abidlabs abidlabs deleted the lite-urllib3-version branch April 14, 2024 17:46
@pngwn pngwn mentioned this pull request Apr 14, 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.

What about async_save_url_to_cache? But this change looks good @whitphx

@abidlabs
Copy link
Member

Oh good catch @freddyaboulton! @whitphx, as @freddyaboulton pointed out, async_save_url_to_cache is used in async_move_files_to_cache, and I think we'll need to patch async_save_url_to_cache to use urllib if running in wasm mode, or otherwise urls that are produced as the result of functions will not be processed correctly

@whitphx
Copy link
Member Author

whitphx commented Apr 15, 2024

Thank you @abidlabs @freddyaboulton ! I missed it.
Will add the same an equivalent patch to it.

@whitphx
Copy link
Member Author

whitphx commented Apr 15, 2024

Made a PR: #8026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio-lite Related to the @gradio/lite library v: minor A change that requires a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lite: Can't load example image from URL
4 participants