Replace httpx with requests library in save_url_to_cache to make it work in wasm mode (#7725)

* Replace httpx with requests library to make it work in wasm mode

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Shubham raj 2024-03-18 13:49:55 +05:30 committed by GitHub
parent aca4892ea5
commit 181f4d05d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Replace httpx with requests library in save_url_to_cache to make it work in wasm mode

View File

@ -13,8 +13,8 @@ from io import BytesIO
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal
import httpx
import numpy as np
import requests
from gradio_client import utils as client_utils
from PIL import Image, ImageOps, PngImagePlugin
@ -190,10 +190,9 @@ 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():
response = requests.get(url, stream=True)
with open(full_temp_file_path, "wb") as f:
for chunk in response.iter_content(chunk_size=256):
f.write(chunk)
return full_temp_file_path