CoolFace
Modelpublic

Itoshi321/road_damage

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
Model Card

from fastapi import FastAPI, UploadFile, File from ultralytics import YOLO import cv2 import numpy as np import shutil from fastapi.responses import JSONResponse import os

app = FastAPI()

Load the trained model

MODELPATH = "potholebest.pt" model = YOLO(MODEL_PATH)

@app.post("/predict/") async def predict(file: UploadFile = File(...)): try: # Save uploaded file filepath = f"temp{file.filename}" with open(file_path, "wb") as buffer: shutil.copyfileobj(file.file, buffer)

# Read video cap = cv2.VideoCapture(filepath) frameresults = []

while cap.isOpened(): ret, frame = cap.read() if not ret: break

results = model(frame) # Run YOLO inference detections = results.pandas().xyxy[0].todict(orient="records") frameresults.append(detections)

cap.release() os.remove(file_path)

return JSONResponse(content={"detections": frameresults}) except Exception as e: return JSONResponse(content={"error": str(e)}, statuscode=500)