Spaces:
Sleeping
Sleeping
File size: 2,454 Bytes
6d73052 fef8a16 928495f f15562f 7468932 5e0990b 7468932 fef8a16 bb3359e 928495f 7468932 743fc77 f15562f bb3359e 928495f f15562f 7468932 928495f f15562f 5e0990b 7468932 5e0990b 7468932 5e0990b 7468932 5e0990b 928495f bb3359e 7468932 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
from fastapi import FastAPI, APIRouter
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
import base64
from pydantic import BaseModel
import time
from facenet_pytorch import InceptionResnetV1, MTCNN
import warnings
import os
import face_compare
warnings.filterwarnings('ignore', category=FutureWarning, module='facenet_pytorch')
mtcnn = MTCNN(keep_all=False, device='cpu')
model = InceptionResnetV1(pretrained='vggface2').eval()
app = FastAPI()
router = APIRouter()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
pdf = 0
class ImageData(BaseModel):
image: str
class ImagesData(BaseModel):
idCard: str
profileImage: str
@router.get("/")
async def index() -> FileResponse:
return FileResponse(path="front/dist/index.html", media_type="text/html")
@router.get("/verification")
async def verif() -> FileResponse:
return FileResponse(path="front/dist/index.html", media_type="text/html")
@router.post("/uploadpdf")
async def upload_pdf(data: ImageData):
header, encoded = data.image.split(',', 1)
binary_data = base64.b64decode(encoded)
# Save the pdf
pdf = binary_data
return {"message": "Image reçue et sauvegardée"}
@router.post("/uploadids")
async def upload_ids(data: ImagesData):
header, encoded1 = data.idCard.split(',', 1)
binary_data1 = base64.b64decode(encoded1)
header, encoded2 = data.profileImage.split(',', 1)
binary_data2 = base64.b64decode(encoded2)
with open("id_card_image.png", "wb") as id_card_file:
id_card_file.write(binary_data1) # Save as PNG (or use correct extension based on header)
with open("profile_image.png", "wb") as profile_file:
profile_file.write(binary_data2) # Save as PNG (or use correct extension based on header)
id_card_abs_path = os.path.abspath("id_card_image.png")
profile_image_abs_path = os.path.abspath("profile_image.png")
output = face_compare.compare_faces(id_card_abs_path, profile_image_abs_path)
if output > 0.6:
return {"message": "Valid"}
else:
return {"message": "Not Valid"}
app.include_router(router)
app.mount("/", StaticFiles(directory="front/dist", html=True), name="static")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) |