|
from sklearn.metrics.pairwise import cosine_similarity |
|
from sentence_transformers import SentenceTransformer |
|
import datasets |
|
import gradio as gr |
|
|
|
model = SentenceTransformer('clip-ViT-B-16') |
|
dataset = datasets.load_dataset('brendenc/celeb-identities') |
|
|
|
def predict(im1, im2): |
|
|
|
embeddings = model.encode([im1, im2]) |
|
sim = cosine_similarity(embeddings) |
|
sim = sim[0, 1] |
|
if sim > 0.75: |
|
return sim, "SAME PERSON, UNLOCK PHONE" |
|
else: |
|
return sim, "DIFFERENT PEOPLE, DON'T UNLOCK" |
|
|
|
|
|
interface = gr.Interface(fn=predict, |
|
inputs= [gr.Image(value = dataset['train']['image'][0], type="pil", source="webcam"), |
|
gr.Image(value = dataset['train']['image'][1], type="pil", source="webcam")], |
|
outputs= [gr.Number(label="Similarity"), |
|
gr.Textbox(label="Message")], |
|
title = 'Face ID', |
|
description = 'This app uses emage embeddings and cosine similarity to function as a Face ID application. Cosine similarity is used, so it ranges from -1 to 1.' |
|
) |
|
|
|
interface.launch(debug=True) |
|
|