Skip to content

Commit 32efd8e

Browse files
ydshiehWauplin
andcommitted
trigger CI for #40889 (#41070)
* Adapt and test huggingface_hub v1.0.0.rc0 * forgot to bump hfh * bump * code quality * code quality * relax dependency table * fix has_file * install hfh 1.0.0.rc0 in circle ci jobs * repostiryo * push to hub now returns a commit url * catch HfHubHTTPError * check commit on branch * add it back * fix ? * remove deprecated test * uncomment another test * trigger * no proxies * many more small changes * fix load PIL Image from httpx * require 1.0.0.rc0 * fix mocked tests * fix others * unchange * unchange * args * Update .circleci/config.yml --------- Co-authored-by: Wauplin <lucainp@gmail.com>
1 parent cbb290e commit 32efd8e

38 files changed

+137
-182
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"GitPython<3.1.19",
115115
"hf-doc-builder>=0.3.0",
116116
"hf_xet",
117-
"huggingface-hub>=0.34.0,<1.0",
117+
"huggingface-hub==1.0.0.rc0",
118118
"importlib_metadata",
119119
"ipadic>=1.0.0,<2.0",
120120
"jinja2>=3.1.0",

src/transformers/audio_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
from io import BytesIO
2626
from typing import Any, Optional, Union
2727

28+
import httpx
2829
import numpy as np
29-
import requests
3030
from packaging import version
3131

3232
from .utils import (
@@ -131,7 +131,9 @@ def load_audio_librosa(audio: Union[str, np.ndarray], sampling_rate=16000, timeo
131131

132132
# Load audio from URL (e.g https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/translate_to_chinese.wav)
133133
if audio.startswith("http://") or audio.startswith("https://"):
134-
audio = librosa.load(BytesIO(requests.get(audio, timeout=timeout).content), sr=sampling_rate)[0]
134+
audio = librosa.load(
135+
BytesIO(httpx.get(audio, follow_redirects=True, timeout=timeout).content), sr=sampling_rate
136+
)[0]
135137
elif os.path.isfile(audio):
136138
audio = librosa.load(audio, sr=sampling_rate)[0]
137139
return audio
@@ -173,7 +175,7 @@ def load_audio_as(
173175
# Load audio bytes from URL or file
174176
audio_bytes = None
175177
if audio.startswith(("http://", "https://")):
176-
response = requests.get(audio, timeout=timeout)
178+
response = httpx.get(audio, follow_redirects=True, timeout=timeout)
177179
response.raise_for_status()
178180
audio_bytes = response.content
179181
elif os.path.isfile(audio):

src/transformers/dependency_versions_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"GitPython": "GitPython<3.1.19",
2424
"hf-doc-builder": "hf-doc-builder>=0.3.0",
2525
"hf_xet": "hf_xet",
26-
"huggingface-hub": "huggingface-hub>=0.34.0,<1.0",
26+
"huggingface-hub": "huggingface-hub==1.0.0.rc0",
2727
"importlib_metadata": "importlib_metadata",
2828
"ipadic": "ipadic>=1.0.0,<2.0",
2929
"jinja2": "jinja2>=3.1.0",

src/transformers/file_utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
This module should not be update anymore and is only left for backward compatibility.
1818
"""
1919

20-
from huggingface_hub import get_full_repo_name # for backward compatibility
21-
from huggingface_hub.constants import HF_HUB_DISABLE_TELEMETRY as DISABLE_TELEMETRY # for backward compatibility
22-
2320
from . import __version__
2421

2522
# Backward compatibility imports, to make sure all those objects can be found in file_utils

src/transformers/image_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from io import BytesIO
2020
from typing import Optional, Union
2121

22+
import httpx
2223
import numpy as np
23-
import requests
2424

2525
from .utils import (
2626
ExplicitEnum,
@@ -462,7 +462,7 @@ def load_image(image: Union[str, "PIL.Image.Image"], timeout: Optional[float] =
462462
if image.startswith("http://") or image.startswith("https://"):
463463
# We need to actually check for a real protocol, otherwise it's impossible to use a local file
464464
# like http_huggingface_co.png
465-
image = PIL.Image.open(BytesIO(requests.get(image, timeout=timeout).content))
465+
image = PIL.Image.open(BytesIO(httpx.get(image, timeout=timeout, follow_redirects=True).content))
466466
elif os.path.isfile(image):
467467
image = PIL.Image.open(image)
468468
else:

src/transformers/modelcard.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pathlib import Path
2222
from typing import Any, Optional, Union
2323

24-
import requests
24+
import httpx
2525
import yaml
2626
from huggingface_hub import model_info
2727
from huggingface_hub.errors import OfflineModeIsEnabled
@@ -380,12 +380,7 @@ def __post_init__(self):
380380
for tag in info.tags:
381381
if tag.startswith("license:"):
382382
self.license = tag[8:]
383-
except (
384-
requests.exceptions.HTTPError,
385-
requests.exceptions.ConnectionError,
386-
HFValidationError,
387-
OfflineModeIsEnabled,
388-
):
383+
except (httpx.HTTPError, HFValidationError, OfflineModeIsEnabled):
389384
pass
390385

391386
def create_model_index(self, metric_mapping):

src/transformers/pipelines/audio_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import subprocess
1515
from typing import Any, Union
1616

17+
import httpx
1718
import numpy as np
18-
import requests
1919

2020
from ..utils import add_end_docstrings, is_torch_available, is_torchaudio_available, is_torchcodec_available, logging
2121
from .base import Pipeline, build_pipeline_init_args
@@ -168,7 +168,7 @@ def preprocess(self, inputs):
168168
if inputs.startswith("http://") or inputs.startswith("https://"):
169169
# We need to actually check for a real protocol, otherwise it's impossible to use a local file
170170
# like http_huggingface_co.png
171-
inputs = requests.get(inputs).content
171+
inputs = httpx.get(inputs, follow_redirects=True).content
172172
else:
173173
with open(inputs, "rb") as f:
174174
inputs = f.read()

src/transformers/pipelines/automatic_speech_recognition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from collections import defaultdict
1515
from typing import TYPE_CHECKING, Any, Optional, Union
1616

17+
import httpx
1718
import numpy as np
18-
import requests
1919

2020
from ..generation import GenerationConfig
2121
from ..tokenization_utils import PreTrainedTokenizer
@@ -355,7 +355,7 @@ def preprocess(self, inputs, chunk_length_s=0, stride_length_s=None):
355355
if inputs.startswith("http://") or inputs.startswith("https://"):
356356
# We need to actually check for a real protocol, otherwise it's impossible to use a local file
357357
# like http_huggingface_co.png
358-
inputs = requests.get(inputs).content
358+
inputs = httpx.get(inputs, follow_redirects=True).content
359359
else:
360360
with open(inputs, "rb") as f:
361361
inputs = f.read()

src/transformers/pipelines/image_to_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ class ImageToImagePipeline(Pipeline):
4646
4747
```python
4848
>>> from PIL import Image
49-
>>> import requests
49+
>>> import httpx
50+
>>> import io
5051
5152
>>> from transformers import pipeline
5253
5354
>>> upscaler = pipeline("image-to-image", model="caidas/swin2SR-classical-sr-x2-64")
54-
>>> img = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
55+
>>> img = Image.open(io.BytesIO(httpx.get("http://images.cocodataset.org/val2017/000000039769.jpg").content))
5556
>>> img = img.resize((64, 64))
5657
>>> upscaled_img = upscaler(img)
5758
>>> img.size

src/transformers/pipelines/video_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from io import BytesIO
1616
from typing import Any, Optional, Union, overload
1717

18-
import requests
18+
import httpx
1919

2020
from ..utils import (
2121
add_end_docstrings,
@@ -142,7 +142,7 @@ def preprocess(self, video, num_frames=None, frame_sampling_rate=1):
142142
num_frames = self.model.config.num_frames
143143

144144
if video.startswith("http://") or video.startswith("https://"):
145-
video = BytesIO(requests.get(video).content)
145+
video = BytesIO(httpx.get(video, follow_redirects=True).content)
146146

147147
container = av.open(video)
148148

0 commit comments

Comments
 (0)