nickmuchi commited on
Commit
9560e15
·
1 Parent(s): bd7880e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -40,20 +40,30 @@ def extract_face(im):
40
  return file_name
41
 
42
  def predict(im1, im2,thresh,model_name):
43
- im1_face = Image.open(im1)
44
- im2_face = Image.open(im2)
45
 
 
 
 
 
 
 
 
 
 
46
  model = load_model(model_name)
47
 
48
  sim=cosine_similarity(model.encode([im1_face,im2_face]))[0][1]
49
 
50
  if sim > thresh:
51
- return sim, "SAME PERSON, UNLOCK PHONE"
52
  else:
53
- return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"
54
 
55
  def load_model(model_name):
 
56
  model = SentenceTransformer(model_name)
 
 
57
 
58
  title = """<h1 id="title">FaceID for Facial Recognition with Face Detector</h1>"""
59
 
@@ -114,13 +124,5 @@ with demo:
114
 
115
  nd_but.click(predict,inputs=[nd_image_input_1,nd_image_input_2,thresh,model_options],outputs=[sim,msg],queue=True)
116
  fd_but.click(predict,inputs=[face_1,face_2,thresh,model_options],outputs=[sim_1,msg_1],queue=True)
117
- # interface = gr.Interface(fn=predict,
118
- # inputs= [gr.Image(type="pil", source="webcam"),
119
- # gr.Image(type="pil", source="webcam")],
120
- # outputs= [gr.Number(label="Similarity"),
121
- # gr.Textbox(label="Message")]
122
- # )
123
-
124
- # interface.launch(debug=True)
125
 
126
  demo.launch(debug=True,enable_queue=True)
 
40
  return file_name
41
 
42
  def predict(im1, im2,thresh,model_name):
 
 
43
 
44
+ if not isinstance(im1,str):
45
+ im1_face = im1
46
+ im2_face = im2
47
+
48
+ else:
49
+
50
+ im1_face = Image.open(im1)
51
+ im2_face = Image.open(im2)
52
+
53
  model = load_model(model_name)
54
 
55
  sim=cosine_similarity(model.encode([im1_face,im2_face]))[0][1]
56
 
57
  if sim > thresh:
58
+ return round(sim,2), "SAME PERSON, UNLOCK PHONE"
59
  else:
60
+ return round(sim,2), "DIFFERENT PEOPLE, DON'T UNLOCK"
61
 
62
  def load_model(model_name):
63
+
64
  model = SentenceTransformer(model_name)
65
+
66
+ return model
67
 
68
  title = """<h1 id="title">FaceID for Facial Recognition with Face Detector</h1>"""
69
 
 
124
 
125
  nd_but.click(predict,inputs=[nd_image_input_1,nd_image_input_2,thresh,model_options],outputs=[sim,msg],queue=True)
126
  fd_but.click(predict,inputs=[face_1,face_2,thresh,model_options],outputs=[sim_1,msg_1],queue=True)
 
 
 
 
 
 
 
 
127
 
128
  demo.launch(debug=True,enable_queue=True)