supun9 commited on
Commit
2583243
1 Parent(s): 3464112

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -25
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) #.split("/")[-1]
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
- images, encodings, no_face, more_face = read_files(files)
25
- face_distances = []
26
- true_images = []
27
- false_images = []
28
- for index in range(len(images)):
29
- results = face_recognition.compare_faces(encodings[index], profile_encoding)
30
- if results[0] == True:
31
- face_distance = face_recognition.face_distance(profile_encoding, encodings[index])
32
- face_distances.append(face_distance)
33
- true_images.append(images[index])
34
- else:
35
- false_images.append(images[index])
36
- score = len(face_distances)/(len(images)+len(no_face)+len(more_face))
37
- text = ""
38
- vals, counts = np.unique(face_distances, return_counts=True)
 
39
 
40
- if (np.std(face_distances)<0.01) or max(counts)>((len(images)+len(no_face)+len(more_face))/2):
41
- text += "Most of the images look similar.\n\n"
42
- if len(false_images)>0:
43
- text += str(len(false_images)) + " of the images do not match with the profile picture.\n"
44
- if len(no_face)>0:
45
- text += "No faces were detected in " + str(len(no_face)) + " images.\n"
46
- if len(more_face)>0:
47
- text += "More than one face were detected in " + str(len(more_face)) + " images."
48
- return {"Percentage of matched images":score}, text, true_images, false_images, no_face, more_face
 
 
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""")