Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Face Registration Endpoint #94

Closed
wants to merge 2 commits into from
Closed
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
25 changes: 25 additions & 0 deletions register_face.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from deepface import DeepFace
from fastapi import FastAPI, File, Form, UploadFile
from pydantic import BaseModel
from pymongo import MongoClient

app = FastAPI()
client = MongoClient("mongodb://localhost:27017/")
db = client["face_recognition"]
users_collection = db["users"]


@app.post("/register/")
async def register_face(image: UploadFile = File(...), name: str = Form(...)):
# Perform face recognition and get face embedding
try:
face_embedding = DeepFace.represent(
img_path=image.file, model_name="Facenet")

# Store face embedding and metadata in MongoDB
user_data = {"name": name, "face_embedding": face_embedding}
users_collection.insert_one(user_data)

return {"message": "Face registered successfully"}
except Exception as e:
return {"error": str(e)}, 500
Loading