huggingfacesrc commited on
Commit
7da3cb9
·
verified ·
1 Parent(s): f377737

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from deepface import DeepFace
3
+ import cv2
4
+ import numpy as np
5
+ import io
6
+
7
+ app = FastAPI()
8
+
9
+ REFERENCE_IMAGE_PATH = "reference.jpg" # Add this manually in Hugging Face Space
10
+
11
+ @app.post("/verify-face/")
12
+ async def verify_face(file: UploadFile = File(...)):
13
+ try:
14
+ contents = await file.read()
15
+ image_array = np.frombuffer(contents, np.uint8)
16
+ img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
17
+
18
+ result = DeepFace.verify(img1_path=img, img2_path=REFERENCE_IMAGE_PATH, model_name="VGG-Face")
19
+
20
+ return {"verified": result["verified"], "distance": result["distance"]}
21
+ except Exception as e:
22
+ return {"error": str(e)}