Skip to content

Commit b5b3192

Browse files
committed
Fix import order and add timeout to requests call
1 parent 62af08b commit b5b3192

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

computer_vision/vision_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
https://huggingface.co/docs/transformers/model_doc/vit
1010
"""
1111

12-
from transformers import ViTImageProcessor, ViTForImageClassification
1312
from PIL import Image
1413
import requests
1514
import torch
15+
from transformers import ViTForImageClassification, ViTImageProcessor
1616

1717

1818
def vision_transformer_demo() -> None:
@@ -24,7 +24,7 @@ def vision_transformer_demo() -> None:
2424
Predicted label: tabby, tabby cat
2525
"""
2626
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cat_sample.jpeg"
27-
image = Image.open(requests.get(url, stream=True).raw)
27+
image = Image.open(requests.get(url, stream=True, timeout=10).raw)
2828

2929
processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
3030
model = ViTForImageClassification.from_pretrained("google/vit-base-patch16-224")

0 commit comments

Comments
 (0)