| | import matplotlib.pyplot as plt |
| | from sentence_transformers import SentenceTransformer |
| | from sklearn.metrics.pairwise import cosine_similarity |
| | import gradio as gr |
| |
|
| | model = SentenceTransformer("clip-ViT-B-16") |
| | def predict(im1, im2): |
| | |
| | embeddings = model.encode([im1,im2]) |
| | cos_sim = cosine_similarity(embeddings) |
| | sim = cos_sim[0][1] |
| | if sim > 0.90: |
| | return sim, "SAME PERSON, UNLOCK PHONE" |
| | else: |
| | return sim, "DIFFERENT PEOPLE, DON'T UNLOCK" |
| |
|
| | interface = gr.Interface(fn=predict, |
| | inputs= [gr.Image(type="pil", source="webcam"), |
| | gr.Image(type="pil",source="webcam")], |
| | title="FaceID App", |
| | description="This is a FaceID app using Sentence Transformer as part of week 3 end to end vision application project on CoRise by Abubakar Abid!", |
| | outputs= [gr.Number(label="Similarity"), |
| | gr.Textbox(label="Message")] |
| | ) |
| |
|
| | interface.launch() |
| |
|