Spaces:
Runtime error
Runtime error
import gradio as gr | |
import matplotlib.pyplot as plt | |
from sentence_transformers import SentenceTransformer | |
from sklearn.metrics.pairwise import cosine_similarity | |
def predict(im1, im2): | |
model, theta = SentenceTransformer('sentence-transformers/clip-ViT-L-14'), 0.55 | |
emb1, emb2 = model.encode(im1), model.encode(im2) | |
sim = cosine_similarity(emb1.reshape(1, -1), emb2.reshape(1, -1))[0][0] | |
if sim > theta: | |
return sim, 'User authenticated. Phone unlocked' | |
else: | |
return sim, 'Unrecognized user. Unable to unlock phone' | |
interface = gr.Interface(fn=predict, | |
inputs= [gr.Image(type="pil", source="webcam"), | |
gr.Image(type="pil", source="webcam")], | |
outputs= [gr.Number(label="Similarity"), | |
gr.Textbox(label="Message")] | |
) | |
interface.launch(debug=True) |