frigate/frigate/api/classification.py

38 lines
1.0 KiB
Python
Raw Normal View History

2024-10-22 15:59:30 +03:00
"""Object classification APIs."""
import logging
2024-10-22 16:46:24 +03:00
from fastapi import APIRouter, Request, UploadFile
from fastapi.responses import JSONResponse
2024-10-22 15:59:30 +03:00
from frigate.api.defs.tags import Tags
2024-10-22 16:46:24 +03:00
from frigate.embeddings import EmbeddingsContext
2024-10-22 15:59:30 +03:00
logger = logging.getLogger(__name__)
router = APIRouter(tags=[Tags.events])
@router.get("/faces")
2024-10-22 16:46:24 +03:00
def get_faces():
return JSONResponse(content={"message": "there are faces"})
@router.post("/faces/{name}")
async def register_face(request: Request, name: str, file: UploadFile):
#if not file.content_type.startswith("image"):
# return JSONResponse(
# status_code=400,
# content={
# "success": False,
# "message": "Only an image can be used to register a face.",
# },
# )
context: EmbeddingsContext = request.app.embeddings
context.register_face(name, await file.read())
return JSONResponse(
status_code=200,
content={"success": True, "message": "Successfully registered face."},
)