schrilax commited on
Commit
9d3ebc8
1 Parent(s): be2af5a

initial commit

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +23 -0
  3. requirements.txt +4 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ from sentence_transformers import SentenceTransformer
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+
6
+ def predict(im1, im2):
7
+ model, theta = SentenceTransformer('sentence-transformers/clip-ViT-L-14'), 0.55
8
+ emb1, emb2 = model.encode(im1), model.encode(im2)
9
+ sim = cosine_similarity(emb1.reshape(1, -1), emb2.reshape(1, -1))[0][0]
10
+
11
+ if sim > theta:
12
+ return sim, "User authenticated. Phone unlocked"
13
+ else:
14
+ return sim, "Unrecognized user. Unable to unlock phone"
15
+
16
+ interface = gr.Interface(fn=predict,
17
+ inputs= [gr.Image(type="pil", source="webcam"),
18
+ gr.Image(type="pil", source="webcam")],
19
+ outputs= [gr.Number(label="Similarity"),
20
+ gr.Textbox(label="Message")]
21
+ )
22
+
23
+ interface.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers==4.18.0
3
+ sentence_transformers==2.2.0
4
+ torch==1.11.0