File size: 1,259 Bytes
c4dd0da 214ca09 c4dd0da 1a0508e 214ca09 e6b657c 1a0508e c4dd0da 1a0508e fc2ba75 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from huggingface_hub import hf_hub_download
from typing import Dict, List, Any
from ultralytics import YOLO
class EndpointHandler():
def __init__(self, path=""):
hf_hub_download(repo_id="Drazcat-AI/galletas", filename="yolov8_galletas/runs/detect/train/weights/best.pt")
self.model = YOLO(hf_hub_download(repo_id="Drazcat-AI/galletas", filename="yolov8_galletas/runs/detect/train/weights/best.pt", local_files_only=True))
def predict_objects(self, image_path):
results = self.model(image_path, imgsz=800)
for result in results:
print(result)
return result
def __call__(self, event, context):
if "image_path" not in event:
return {
"statusCode": 400,
"body": json.dumps("Error: Please provide an 'image_path' parameter."),
}
image_path = event["image_path"]
try:
predictions = self.predict_objects(image_path)
return {
"statusCode": 200,
"body": json.dumps(predictions),
}
except Exception as e:
return {
"statusCode": 500,
"body": json.dumps(f"Error: {str(e)}"),
} |