Skip to content

Commit

Permalink
Add an explicit dependency of urllib3~=2.0 and update `processing_u…
Browse files Browse the repository at this point in the history
…tils.save_url_to_cache` to use `urllib3` for Lite support (#8011)

* Add an explicit dependency of `urllib3` and update `processing_utils.save_url_to_cache` to use `urllib3` for Lite support

* add changeset

* Update requirements.txt

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* add changeset

* update test requirements

* update test reqs

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people committed Apr 14, 2024
1 parent e10ec6a commit f17d1a0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-melons-follow.md
@@ -0,0 +1,5 @@
---
"gradio": minor
---

fix:Add an explicit dependency of `urllib3~=2.0` and update `processing_utils.save_url_to_cache` to use `urllib3` for Lite support
14 changes: 10 additions & 4 deletions gradio/processing_utils.py
Expand Up @@ -16,6 +16,7 @@
import aiofiles
import httpx
import numpy as np
import urllib3
from gradio_client import utils as client_utils
from PIL import Image, ImageOps, PngImagePlugin

Expand Down Expand Up @@ -208,10 +209,15 @@ def save_url_to_cache(url: str, cache_dir: str) -> str:
full_temp_file_path = str(abspath(temp_dir / name))

if not Path(full_temp_file_path).exists():
with httpx.stream("GET", url, follow_redirects=True) as r, open(
full_temp_file_path, "wb"
) as f:
for chunk in r.iter_raw():
# NOTE: We use urllib3 instead of httpx because it works in the Wasm environment. See https://github.com/gradio-app/gradio/issues/6837.
http = urllib3.PoolManager()
response = http.request(
"GET",
url,
preload_content=False,
)
with open(full_temp_file_path, "wb") as f:
for chunk in response.stream():
f.write(chunk)

return full_temp_file_path
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -20,6 +20,7 @@ pydub
pyyaml>=5.0,<7.0
semantic_version~=2.0
typing_extensions~=4.0
urllib3~=2.0 # urllib3 is used for Lite support. Version spec can be omitted because urllib3==2.1.0 is prebuilt for Pyodide and urllib>=2.2.0 supports Pyodide as well.
uvicorn>=0.14.0; sys.platform != 'emscripten'
typer[all]>=0.9,<1.0; sys.platform != 'emscripten'
tomlkit==0.12.0
Expand Down
6 changes: 3 additions & 3 deletions test/requirements.txt
Expand Up @@ -26,9 +26,9 @@ attrs==21.4.0
# pytest
backcall==0.2.0
# via ipython
boto3==1.26.65
boto3==1.34.84
# via -r requirements.in
botocore==1.29.87
botocore==1.34.84
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -273,7 +273,7 @@ ruff==0.2.2
# via
# -r requirements.in
# gradio
s3transfer==0.6.0
s3transfer==0.10.0
# via boto3
safetensors==0.4.2
# via
Expand Down

0 comments on commit f17d1a0

Please sign in to comment.