Download handler.py from skumar1998/yolotesting: direct link, hf CLI and curl.
- Browser
- Download file 889 Bytes
-
https://huggingface.co/skumar1998/yolotesting/resolve/79bd3063f2db7cd2d8720bcbc021cda5318bae3f/handler.py
- Command line
-
hf download hf://skumar1998/yolotesting@79bd3063f2db7cd2d8720bcbc021cda5318bae3f/handler.py
-
curl -L -o handler.py https://huggingface.co/skumar1998/yolotesting/resolve/79bd3063f2db7cd2d8720bcbc021cda5318bae3f/handler.py
889 Bytes
| from typing import Dict | |
| from ultralytics import YOLO | |
| import requests | |
| from io import BytesIO | |
| from PIL import Image | |
| import time | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| # load the model | |
| print('Loading the yolo model') | |
| model_path = "yolov8m_detect_usdl.pt" | |
| self.model = YOLO(model_path) | |
| print('Yolo model loaded successfully') | |
| def __call__(self, data: Dict) -> Dict: | |
| image_url = data.get('image_url') | |
| print(f'Image url is : {image_url}') | |
| response = requests.get(image_url) | |
| pil_image = Image.open(BytesIO(response.content)) | |
| print('Model inference started....') | |
| t1 = time.time() | |
| results = self.model(pil_image) | |
| print(f'TIME Model inference: {time.time() - t1}') | |
| # postprocess the prediction | |
| return {"bbox": results[0].boxes.data.tolist()} |