Actually send result to face registration

This commit is contained in:
Nicolas Mowen 2025-01-10 06:47:02 -07:00
parent f1f3d46d9c
commit 8efdd8487a
3 changed files with 17 additions and 8 deletions

View File

@ -40,10 +40,10 @@ def get_faces():
@router.post("/faces/{name}")
async def register_face(request: Request, name: str, file: UploadFile):
context: EmbeddingsContext = request.app.embeddings
context.register_face(name, await file.read())
result = context.register_face(name, await file.read())
return JSONResponse(
status_code=200,
content={"success": True, "message": "Successfully registered face."},
status_code=200 if result.get("success", True) else 400,
content=result,
)

View File

@ -192,8 +192,8 @@ class EmbeddingsContext:
return results
def register_face(self, face_name: str, image_data: bytes) -> None:
self.requestor.send_data(
def register_face(self, face_name: str, image_data: bytes) -> dict[str, any]:
return self.requestor.send_data(
EmbeddingsRequestEnum.register_face.value,
{
"face_name": face_name,

View File

@ -144,7 +144,10 @@ class EmbeddingMaintainer(threading.Thread):
)
elif topic == EmbeddingsRequestEnum.register_face.value:
if not self.face_recognition_enabled:
return False
return {
"message": "Face recognition is not enabled.",
"success": False,
}
rand_id = "".join(
random.choices(string.ascii_lowercase + string.digits, k=6)
@ -164,7 +167,10 @@ class EmbeddingMaintainer(threading.Thread):
face_box = self._detect_face(img)
if not face_box:
return False
return {
"message": "No face was detected.",
"success": False,
}
face = img[face_box[1] : face_box[3], face_box[0] : face_box[2]]
ret, thumbnail = cv2.imencode(
@ -181,7 +187,10 @@ class EmbeddingMaintainer(threading.Thread):
output.write(thumbnail.tobytes())
self.face_classifier.clear_classifier()
return True
return {
"message": "Successfully registered face.",
"success": True,
}
except Exception as e:
logger.error(f"Unable to handle embeddings request {e}")