Hitesh Karunakara Shetty
commited on
Commit
·
6c064b0
1
Parent(s):
0c677aa
FaceID files
Browse files- app.py +24 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
model = SentenceTransformer("clip-ViT-B-16")
|
7 |
+
def predict(im1, im2):
|
8 |
+
# ANSWER HERE
|
9 |
+
embeddings = model.encode([im1,im2])
|
10 |
+
cos_sim = cosine_similarity(embeddings)
|
11 |
+
sim = cos_sim[0][1]
|
12 |
+
if sim > 0.80:# THRESHOLD HERE
|
13 |
+
return sim, "SAME PERSON, UNLOCK PHONE"
|
14 |
+
else:
|
15 |
+
return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"
|
16 |
+
|
17 |
+
interface = gr.Interface(fn=predict,
|
18 |
+
inputs= [gr.Image(type="pil", source="webcam"),
|
19 |
+
gr.Image(type="pil",source="webcam")],
|
20 |
+
outputs= [gr.Number(label="Similarity"),
|
21 |
+
gr.Textbox(label="Message")]
|
22 |
+
)
|
23 |
+
|
24 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib
|
2 |
+
sentence_transformers
|
3 |
+
sklearn
|
4 |
+
gradio
|