Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ def read_files(files):
|
|
8 |
no_face = []
|
9 |
more_face = []
|
10 |
for idx, image in enumerate(files):
|
11 |
-
image = face_recognition.load_image_file(image.name)
|
12 |
encoding = face_recognition.face_encodings(image)
|
13 |
if len(encoding)==1:
|
14 |
images.append(image)
|
@@ -21,31 +21,34 @@ def read_files(files):
|
|
21 |
|
22 |
def read(profile, files):
|
23 |
profile_encoding = face_recognition.face_encodings(profile)
|
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 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown("""# Face Verification System""")
|
|
|
8 |
no_face = []
|
9 |
more_face = []
|
10 |
for idx, image in enumerate(files):
|
11 |
+
image = face_recognition.load_image_file(image.name)
|
12 |
encoding = face_recognition.face_encodings(image)
|
13 |
if len(encoding)==1:
|
14 |
images.append(image)
|
|
|
21 |
|
22 |
def read(profile, files):
|
23 |
profile_encoding = face_recognition.face_encodings(profile)
|
24 |
+
if len(profile_encoding)==1:
|
25 |
+
images, encodings, no_face, more_face = read_files(files)
|
26 |
+
face_distances = []
|
27 |
+
true_images = []
|
28 |
+
false_images = []
|
29 |
+
for index in range(len(images)):
|
30 |
+
results = face_recognition.compare_faces(encodings[index], profile_encoding)
|
31 |
+
if results[0] == True:
|
32 |
+
face_distance = face_recognition.face_distance(profile_encoding, encodings[index])
|
33 |
+
face_distances.append(face_distance)
|
34 |
+
true_images.append(images[index])
|
35 |
+
else:
|
36 |
+
false_images.append(images[index])
|
37 |
+
score = len(face_distances)/(len(images)+len(no_face)+len(more_face))
|
38 |
+
text = ""
|
39 |
+
vals, counts = np.unique(face_distances, return_counts=True)
|
40 |
|
41 |
+
if (np.std(face_distances)<0.01) or max(counts)>((len(images)+len(no_face)+len(more_face))/2):
|
42 |
+
text += "Most of the images look similar.\n\n"
|
43 |
+
if len(false_images)>0:
|
44 |
+
text += str(len(false_images)) + " of the images do not match with the profile picture.\n"
|
45 |
+
if len(no_face)>0:
|
46 |
+
text += "No faces were detected in " + str(len(no_face)) + " images.\n"
|
47 |
+
if len(more_face)>0:
|
48 |
+
text += "More than one face were detected in " + str(len(more_face)) + " images."
|
49 |
+
return {"Percentage of matched images":score}, text, true_images, false_images, no_face, more_face
|
50 |
+
else:
|
51 |
+
return {"Percentage of matched images":0}, "No faces or more than one faces are detected in the profile picture", [], [], [], []
|
52 |
|
53 |
with gr.Blocks() as demo:
|
54 |
gr.Markdown("""# Face Verification System""")
|