MingDoan's picture
feat: First commit
65aa0cb
raw
history blame contribute delete
765 Bytes
from fastapi import APIRouter, UploadFile, File, HTTPException, status
from fastapi.responses import JSONResponse
from .model import Detections
from .controller import detect_object
router = APIRouter(
prefix="/detection",
tags=["detection"],
default_response_class=JSONResponse
)
@router.post("/", response_model=Detections)
async def detection(
image: UploadFile = File(..., description="File to detect"),
):
if not image.content_type.startswith("image"):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid file type. Only image files are allowed."
)
# Read image file
contents = await image.read()
detections = detect_object(contents)
return detections