Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 15, 2024
1 parent 8c9570e commit 46fb95b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions register_face.py
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

0 comments on commit 46fb95b

Please sign in to comment.