Revert "Replace httpx with requests library in save_url_to_cache to make it w…" (#7729)

This reverts commit 181f4d05d4.

Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
This commit is contained in:
Abubakar Abid 2024-03-18 08:03:02 -07:00 committed by GitHub
parent 7d3c868d0a
commit c5d20483b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 9 deletions

View File

@ -1,5 +0,0 @@
---
"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,9 +190,10 @@ 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():
response = requests.get(url, stream=True)
with open(full_temp_file_path, "wb") as f:
for chunk in response.iter_content(chunk_size=256):
with httpx.stream("GET", url, follow_redirects=True) as r, open(
full_temp_file_path, "wb"
) as f:
for chunk in r.iter_raw():
f.write(chunk)
return full_temp_file_path