-
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.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
8c9570e
commit 46fb95b
Showing
1 changed file
with
11 additions
and
12 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 |
---|---|---|
@@ -1,26 +1,25 @@ | ||
from fastapi import FastAPI, File, UploadFile, Form | ||
from deepface import DeepFace | ||
from pymongo import MongoClient | ||
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'] | ||
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') | ||
|
||
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 | ||
} | ||
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 |