Download app.py from tadeyina/Face_Id_Application: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/tadeyina/Face_Id_Application/resolve/main/app.py
- Command line
-
hf download hf://tadeyina/Face_Id_Application/app.py
-
curl -L -o app.py https://huggingface.co/tadeyina/Face_Id_Application/resolve/main/app.py
1.18 kB
| 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('tadeyina/celeb-identities') | |
| def predict(im1, im2): | |
| embeddings = model.encode([im1, im2]) | |
| sim = cosine_similarity(embeddings) | |
| sim = sim[0, 1] | |
| if sim > 0.8: | |
| 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) | |