Spaces:
Runtime error
Runtime error
Commit
·
d77636f
1
Parent(s):
f3ef69f
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
model = SentenceTransformer('clip-ViT-B-32')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict(im1, im2):
|
| 13 |
+
embeding = model.encode([im1, im2])
|
| 14 |
+
sim = cosine_similarity(embeding)
|
| 15 |
+
sim = sim[0][1]
|
| 16 |
+
if sim > 0.78: # THRESHOLD HERE
|
| 17 |
+
return sim, "SAME PERSON, UNLOCK PHONE"
|
| 18 |
+
else:
|
| 19 |
+
return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
title = 'Face ID'
|
| 24 |
+
description = 'This model detects the similarity between two images and passes a command!'
|
| 25 |
+
interface = gr.Interface(fn=predict,
|
| 26 |
+
inputs= [gr.Image(type="pil", source="webcam"),
|
| 27 |
+
gr.Image(type="pil", source="webcam")],
|
| 28 |
+
outputs= [gr.Number(label="Similarity"),
|
| 29 |
+
gr.Textbox(label="Message")],
|
| 30 |
+
title = title,
|
| 31 |
+
description = description
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
interface.launch(debug=True)
|