|
|
@@ -1,14 +1,14 @@
|
|
|
+import sys
|
|
|
import tempfile
|
|
|
import grpc
|
|
|
-import sys
|
|
|
from concurrent import futures
|
|
|
import os
|
|
|
from deepface import DeepFace
|
|
|
|
|
|
+
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "proto"))
|
|
|
+from proto import face_recognition_pb2, face_recognition_pb2_grpc
|
|
|
|
|
|
-from proto import face_recognition_pb2
|
|
|
-from proto import face_recognition_pb2_grpc
|
|
|
|
|
|
EMPLOYEE_DB_PATH = "data/employees"
|
|
|
|
|
|
@@ -75,7 +75,43 @@ class FaceRecognitionServicer(face_recognition_pb2_grpc.FaceRecognitionServiceSe
|
|
|
try:
|
|
|
os.remove(temp_file)
|
|
|
except Exception as cleanup_error:
|
|
|
- print(f"[WARN] Could not delete temp file {temp_file}: {cleanup_error}")
|
|
|
+ print(
|
|
|
+ f"[WARN] Could not delete temp file {temp_file}: {cleanup_error}")
|
|
|
+
|
|
|
+ def EnrollFace(self, request, context):
|
|
|
+ """
|
|
|
+ Handles enrollment of a new employee.
|
|
|
+ Saves the uploaded image in EMPLOYEE_DB_PATH with the employee's name.
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ name = request.name
|
|
|
+ image_bytes = request.image
|
|
|
+
|
|
|
+ if not name or not image_bytes:
|
|
|
+ return face_recognition_pb2.EnrollFaceResponse(
|
|
|
+ success=False,
|
|
|
+ message="Name or image missing"
|
|
|
+ )
|
|
|
+
|
|
|
+ os.makedirs(EMPLOYEE_DB_PATH, exist_ok=True)
|
|
|
+ file_path = os.path.join(EMPLOYEE_DB_PATH, f"{name}.jpg")
|
|
|
+
|
|
|
+ with open(file_path, "wb") as f:
|
|
|
+ f.write(image_bytes)
|
|
|
+
|
|
|
+ print(f"[INFO] Enrolled employee: {name}, saved at {file_path}")
|
|
|
+
|
|
|
+ return face_recognition_pb2.EnrollFaceResponse(
|
|
|
+ success=True,
|
|
|
+ message="Enrollment successful"
|
|
|
+ )
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[ERROR] Enrollment failed: {e}")
|
|
|
+ return face_recognition_pb2.EnrollFaceResponse(
|
|
|
+ success=False,
|
|
|
+ message=str(e)
|
|
|
+ )
|
|
|
|
|
|
def GetAllEmployees(self, request, context):
|
|
|
try:
|