Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI,UploadFile,File | |
| import numpy as np | |
| from ultralytics import YOLO | |
| import cv2 | |
| app = FastAPI() | |
| model = YOLO("models/yolo11n-cls.pt") | |
| def home(): | |
| return {"message", "YOLO FastAPI Server Running"} | |
| async def classify_image(file:UploadFile = File(...)): | |
| contents = await file.read() | |
| nparr = np.frombuffer(contents, np.uint8) | |
| img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) | |
| results = model(img) | |
| return { | |
| "detect image in class":results[0].names[results[0].probs.top1], | |
| "confidence":f"{results[0].probs.top1conf.item():.2f}" | |
| } | |