-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76ac737
commit 8c9570e
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |