Skip to content

Commit

Permalink
Create register_face.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin2815 authored Oct 15, 2024
1 parent 76ac737 commit 8c9570e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions register_face.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from fastapi import FastAPI, File, UploadFile, Form
from deepface import DeepFace
from pymongo import MongoClient
from pydantic import BaseModel

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

0 comments on commit 8c9570e

Please sign in to comment.