Skip to content

Commit 407e72a

Browse files
authored
Upgrade from httpx to httpx2
Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 8f24c2a commit 407e72a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

computer_vision/vision_transformer_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- torch
1313
- transformers
1414
- Pillow (PIL)
15-
- httpx (already in repo dependencies)
15+
- httpx2 (already in repo dependencies)
1616
1717
Resources:
1818
- Paper: https://arxiv.org/abs/2010.11929
@@ -40,7 +40,7 @@
4040
from typing import Any
4141

4242
try:
43-
import httpx
43+
import httpx2
4444
import torch
4545
from PIL import Image
4646
from transformers import ViTForImageClassification, ViTImageProcessor
@@ -79,17 +79,17 @@ def load_image(image_source: str | Path, timeout: int = 10) -> Image.Image:
7979
("http://", "https://")
8080
):
8181
try:
82-
with httpx.Client(timeout=timeout) as client:
82+
with httpx2.Client(timeout=timeout) as client:
8383
response = client.get(str(image_source))
8484
response.raise_for_status()
8585
return Image.open(BytesIO(response.content)).convert("RGB")
86-
except httpx.TimeoutException:
86+
except httpx2.TimeoutException:
8787
msg = (
8888
f"Request timed out after {timeout} seconds. "
8989
"Try increasing the timeout parameter."
9090
)
9191
raise TimeoutError(msg)
92-
except httpx.HTTPError as e:
92+
except httpx2.HTTPError as e:
9393
msg = f"Failed to download image from URL: {e}"
9494
raise ConnectionError(msg) from e
9595
else:

0 commit comments

Comments
 (0)