Spaces:
Runtime error
Runtime error
File size: 907 Bytes
9d3ebc8 6f36334 9d3ebc8 6f36334 9d3ebc8 9714130 9d3ebc8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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) |