Spaces:
Sleeping
Sleeping
File size: 765 Bytes
65aa0cb |
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 |
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
|