Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions backend/app/utils/faceSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ def perform_face_search(image_path: str) -> GetAllImagesResponse:
Returns:
GetAllImagesResponse: Search result containing matched images.
"""
fd = FaceDetector()
fn = FaceNet(DEFAULT_FACENET_MODEL)
fd = None
fn = None

try:
fd = FaceDetector()
fn = FaceNet(DEFAULT_FACENET_MODEL)

matches = []
image_id = str(uuid.uuid4())

Expand Down Expand Up @@ -99,8 +102,15 @@ def perform_face_search(image_path: str) -> GetAllImagesResponse:
data=matches,
)

except Exception as e:
return GetAllImagesResponse(
success=False,
message=f"Failed to initialize models: {str(e)}",
data=[],
)

finally:
if "fd" in locals() and fd is not None:
if fd is not None:
fd.close()
if "fn" in locals() and fn is not None:
if fn is not None:
fn.close()