File size: 2,026 Bytes
6d73052
fef8a16
 
928495f
f15562f
 
 
7468932
 
 
 
 
 
 
 
 
fef8a16
 
bb3359e
 
928495f
 
 
 
 
 
 
 
7468932
743fc77
f15562f
 
 
 
 
 
 
bb3359e
 
 
 
 
 
 
928495f
f15562f
 
 
7468932
 
 
928495f
 
 
f15562f
7468932
 
 
 
 
 
 
 
 
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
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 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)
    output = face_compare.compare_faces(binary_data1, binary_data2)
    if output > 0.6:
        return {"message": "Les images correspondent"}
    else:
        return {"message": "Les images ne correspondent pas"}

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)