Spaces:
No application file
No application file
Download app.py from huggingfacesrc/facial-auth-api: direct link, hf CLI and curl.
- Browser
- Download file 800 Bytes
-
https://huggingface.co/spaces/huggingfacesrc/facial-auth-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/huggingfacesrc/facial-auth-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/huggingfacesrc/facial-auth-api/resolve/main/app.py
800 Bytes
| from fastapi import FastAPI, UploadFile, File | |
| from deepface import DeepFace | |
| import cv2 | |
| import numpy as np | |
| import io | |
| import uvicorn | |
| app = FastAPI() | |
| REFERENCE_IMAGE_PATH = "reference.jpg" # Add this manually in Hugging Face Space | |
| async def verify_face(file: UploadFile = File(...)): | |
| try: | |
| contents = await file.read() | |
| image_array = np.frombuffer(contents, np.uint8) | |
| img = cv2.imdecode(image_array, cv2.IMREAD_COLOR) | |
| result = DeepFace.verify(img1_path=img, img2_path=REFERENCE_IMAGE_PATH, model_name="VGG-Face") | |
| return {"verified": result["verified"], "distance": result["distance"]} | |
| except Exception as e: | |
| return {"error": str(e)} | |
| if __name__ == __main__(): | |
| uvicorn.run(app , host = "0.0.0.0" , port = 8080) | |