Spaces:
Sleeping
Sleeping
pierrelissope
commited on
Commit
·
5e0990b
1
Parent(s):
94f7100
feat: c'est carré on a fini
Browse files- front/dist/index.html +2 -2
- front/src/VerificationScene.tsx +5 -3
- front/src/components/ResultContainer.tsx +9 -4
- main.py +15 -3
front/dist/index.html
CHANGED
@@ -5,8 +5,8 @@
|
|
5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
<title>Vite + React + TS</title>
|
8 |
-
<script type="module" crossorigin src="/assets/index-
|
9 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
10 |
</head>
|
11 |
<body>
|
12 |
<div id="root"></div>
|
|
|
5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
<title>Vite + React + TS</title>
|
8 |
+
<script type="module" crossorigin src="/assets/index-D1zI8xqC.js"></script>
|
9 |
+
<link rel="stylesheet" crossorigin href="/assets/index-FOeRIyQ0.css">
|
10 |
</head>
|
11 |
<body>
|
12 |
<div id="root"></div>
|
front/src/VerificationScene.tsx
CHANGED
@@ -5,6 +5,8 @@ import VideoWrapper from "@/components/VideoWrapper.tsx";
|
|
5 |
import ResultContainer from "@/components/ResultContainer.tsx";
|
6 |
import DarkVideoWrapper from "@/components/DarkVideoWrapper.tsx";
|
7 |
|
|
|
|
|
8 |
enum StepType {
|
9 |
takeId,
|
10 |
verifyId,
|
@@ -39,7 +41,7 @@ export default function VerificationScene() {
|
|
39 |
const sendImageToServer = async (
|
40 |
idCard: string,
|
41 |
profileImage: string,
|
42 |
-
setLoading: (n:
|
43 |
) => {
|
44 |
try {
|
45 |
const response = await fetch("http://0.0.0.0:7860/uploadids", {
|
@@ -56,10 +58,10 @@ export default function VerificationScene() {
|
|
56 |
|
57 |
const data = await response.json();
|
58 |
console.log("Image envoyée avec succès:", data);
|
59 |
-
setLoading(
|
60 |
} catch (error) {
|
61 |
console.error("Erreur:", error);
|
62 |
-
setLoading(
|
63 |
}
|
64 |
};
|
65 |
|
|
|
5 |
import ResultContainer from "@/components/ResultContainer.tsx";
|
6 |
import DarkVideoWrapper from "@/components/DarkVideoWrapper.tsx";
|
7 |
|
8 |
+
export type fetchResult = "Valid" | "Not Valid" | "Fetching" | "Error";
|
9 |
+
|
10 |
enum StepType {
|
11 |
takeId,
|
12 |
verifyId,
|
|
|
41 |
const sendImageToServer = async (
|
42 |
idCard: string,
|
43 |
profileImage: string,
|
44 |
+
setLoading: (n: fetchResult) => void,
|
45 |
) => {
|
46 |
try {
|
47 |
const response = await fetch("http://0.0.0.0:7860/uploadids", {
|
|
|
58 |
|
59 |
const data = await response.json();
|
60 |
console.log("Image envoyée avec succès:", data);
|
61 |
+
setLoading(data.message === "Valid" ? "Valid" : "Not Valid");
|
62 |
} catch (error) {
|
63 |
console.error("Erreur:", error);
|
64 |
+
setLoading("Error");
|
65 |
}
|
66 |
};
|
67 |
|
front/src/components/ResultContainer.tsx
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import { useEffect, useState } from "react";
|
|
|
2 |
|
3 |
export default function ResultContainer({
|
4 |
sendImageToServer,
|
@@ -8,22 +9,26 @@ export default function ResultContainer({
|
|
8 |
sendImageToServer: (
|
9 |
pic: string,
|
10 |
pic2: string,
|
11 |
-
setLoading: (n:
|
12 |
) => void;
|
13 |
idCardPicture: string;
|
14 |
profileImage: string;
|
15 |
}) {
|
16 |
-
const [loading, setLoading] = useState<
|
17 |
|
18 |
useEffect(() => {
|
19 |
sendImageToServer(idCardPicture ?? "", profileImage ?? "", setLoading);
|
20 |
}, []);
|
21 |
return (
|
22 |
<div className="flex w-full h-full items-center justify-center">
|
23 |
-
{loading ? (
|
24 |
<h1 className="text-2xl font-bold text-orange-600">Fetching....</h1>
|
|
|
|
|
|
|
|
|
25 |
) : (
|
26 |
-
<h1 className="text-2xl
|
27 |
)}
|
28 |
</div>
|
29 |
);
|
|
|
1 |
import { useEffect, useState } from "react";
|
2 |
+
import { fetchResult } from "@/VerificationScene.tsx";
|
3 |
|
4 |
export default function ResultContainer({
|
5 |
sendImageToServer,
|
|
|
9 |
sendImageToServer: (
|
10 |
pic: string,
|
11 |
pic2: string,
|
12 |
+
setLoading: (n: fetchResult) => void,
|
13 |
) => void;
|
14 |
idCardPicture: string;
|
15 |
profileImage: string;
|
16 |
}) {
|
17 |
+
const [loading, setLoading] = useState<fetchResult>("Fetching");
|
18 |
|
19 |
useEffect(() => {
|
20 |
sendImageToServer(idCardPicture ?? "", profileImage ?? "", setLoading);
|
21 |
}, []);
|
22 |
return (
|
23 |
<div className="flex w-full h-full items-center justify-center">
|
24 |
+
{loading === "Fetching" ? (
|
25 |
<h1 className="text-2xl font-bold text-orange-600">Fetching....</h1>
|
26 |
+
) : loading === "Valid" ? (
|
27 |
+
<h1 className="text-2xl font-bold text-green-800">Valid</h1>
|
28 |
+
) : loading === "Not Valid" ? (
|
29 |
+
<h1 className="text-2xl font-bold text-green-800">Not Valid</h1>
|
30 |
) : (
|
31 |
+
<h1 className="text-2xl text-red-700">Error</h1>
|
32 |
)}
|
33 |
</div>
|
34 |
);
|
main.py
CHANGED
@@ -7,6 +7,7 @@ from pydantic import BaseModel
|
|
7 |
import time
|
8 |
from facenet_pytorch import InceptionResnetV1, MTCNN
|
9 |
import warnings
|
|
|
10 |
import face_compare
|
11 |
|
12 |
warnings.filterwarnings('ignore', category=FutureWarning, module='facenet_pytorch')
|
@@ -53,15 +54,26 @@ async def upload_pdf(data: ImageData):
|
|
53 |
|
54 |
@router.post("/uploadids")
|
55 |
async def upload_ids(data: ImagesData):
|
|
|
56 |
header, encoded1 = data.idCard.split(',', 1)
|
57 |
binary_data1 = base64.b64decode(encoded1)
|
58 |
header, encoded2 = data.profileImage.split(',', 1)
|
59 |
binary_data2 = base64.b64decode(encoded2)
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
if output > 0.6:
|
62 |
-
return {"message": "
|
63 |
else:
|
64 |
-
return {"message": "
|
65 |
|
66 |
app.include_router(router)
|
67 |
|
|
|
7 |
import time
|
8 |
from facenet_pytorch import InceptionResnetV1, MTCNN
|
9 |
import warnings
|
10 |
+
import os
|
11 |
import face_compare
|
12 |
|
13 |
warnings.filterwarnings('ignore', category=FutureWarning, module='facenet_pytorch')
|
|
|
54 |
|
55 |
@router.post("/uploadids")
|
56 |
async def upload_ids(data: ImagesData):
|
57 |
+
|
58 |
header, encoded1 = data.idCard.split(',', 1)
|
59 |
binary_data1 = base64.b64decode(encoded1)
|
60 |
header, encoded2 = data.profileImage.split(',', 1)
|
61 |
binary_data2 = base64.b64decode(encoded2)
|
62 |
+
|
63 |
+
with open("id_card_image.png", "wb") as id_card_file:
|
64 |
+
id_card_file.write(binary_data1) # Save as PNG (or use correct extension based on header)
|
65 |
+
|
66 |
+
with open("profile_image.png", "wb") as profile_file:
|
67 |
+
profile_file.write(binary_data2) # Save as PNG (or use correct extension based on header)
|
68 |
+
|
69 |
+
id_card_abs_path = os.path.abspath("id_card_image.png")
|
70 |
+
profile_image_abs_path = os.path.abspath("profile_image.png")
|
71 |
+
|
72 |
+
output = face_compare.compare_faces(id_card_abs_path, profile_image_abs_path)
|
73 |
if output > 0.6:
|
74 |
+
return {"message": "Valid"}
|
75 |
else:
|
76 |
+
return {"message": "Not Valid"}
|
77 |
|
78 |
app.include_router(router)
|
79 |
|