npc0 commited on
Commit
255703a
·
1 Parent(s): ddb6238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -46,6 +46,20 @@ for f in os.listdir("data"):
46
  # known_persons.append(os.path.splitext(os.path.basename(f))[0])
47
  known_persons.append(os.path.basename(f))
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  import gradio as gr
51
 
@@ -63,6 +77,10 @@ def greet(image_to_test):
63
  os.path.splitext(filepath)[0],
64
  100 * (1 - face_distance))
65
  img = face_recognition.load_image_file(os.path.join("data", filepath))
 
 
 
 
66
  return img, ret
67
 
68
  iface = gr.Interface(fn=greet, inputs=gr.Image(source="webcam", streaming=True, type="numpy"), outputs=["image", "text"])
 
46
  # known_persons.append(os.path.splitext(os.path.basename(f))[0])
47
  known_persons.append(os.path.basename(f))
48
 
49
+ import tempfile
50
+ from face_symmetrizer import FaceSym
51
+
52
+ def left_right_sim(img):
53
+ tmpf = tempfile.NamedTemporaryFile(delete=False)
54
+ img.save(tmpf.name, format='png')
55
+ f = FaceSym(tmpf.name)
56
+ _, left, _, _, right, _ = f.get_symmetrized_images(idx=0)
57
+ tmpf.close()
58
+ os.unlink(tmpf.name)
59
+ left_encoding = face_recognition.face_encodings(left)[0]
60
+ right_encoding = face_recognition.face_encodings(right)[0]
61
+ diff = face_recognition.face_distance([left_encoding], right_encoding)
62
+ return 100 * (1 - diff)
63
 
64
  import gradio as gr
65
 
 
77
  os.path.splitext(filepath)[0],
78
  100 * (1 - face_distance))
79
  img = face_recognition.load_image_file(os.path.join("data", filepath))
80
+ ret += "\n\n \
81
+ The similarity (symmetry score) of \
82
+ left and right face = {:.3}".format(
83
+ left_right_sim(image_to_test))
84
  return img, ret
85
 
86
  iface = gr.Interface(fn=greet, inputs=gr.Image(source="webcam", streaming=True, type="numpy"), outputs=["image", "text"])