Spaces:
Running
Running
Dhritiman Sagar
commited on
Commit
•
019de41
1
Parent(s):
3878cca
Initial commit
Browse files- app.py +32 -0
- requirements.txt +10 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
import transformers
|
6 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
7 |
+
from sklearn.metrics import silhouette_score
|
8 |
+
from sentence_transformers import SentenceTransformer
|
9 |
+
|
10 |
+
model = SentenceTransformer("clip-ViT-L-14")
|
11 |
+
|
12 |
+
def predict(im1, im2):
|
13 |
+
embeddings = [model.encode(im1), model.encode(im2)]
|
14 |
+
sim = cosine_similarity(embeddings[0].reshape(1, -1), embeddings[1].reshape(1, -1)).squeeze()
|
15 |
+
if sim > 0.80:
|
16 |
+
return sim, "SAME PERSON, UNLOCK PHONE"
|
17 |
+
else:
|
18 |
+
return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"
|
19 |
+
|
20 |
+
import gradio as gr
|
21 |
+
|
22 |
+
interface = gr.Interface(fn=predict,
|
23 |
+
inputs=[gr.Image(type="pil", source="webcam"),
|
24 |
+
gr.Image(type="pil", source="webcam")],
|
25 |
+
outputs=[gr.Number(label="Similarity"),
|
26 |
+
gr.Textbox(label="Message")],
|
27 |
+
title='Basic Face-Id',
|
28 |
+
description='A very simple face-id implementation using sentence-transformer embeddings.',
|
29 |
+
)
|
30 |
+
|
31 |
+
interface.launch()
|
32 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
numpy
|
3 |
+
torchvision
|
4 |
+
torchaudio
|
5 |
+
datasets
|
6 |
+
sentence
|
7 |
+
transformers
|
8 |
+
sentence-transformers
|
9 |
+
evaluate
|
10 |
+
gradio
|