File size: 1,474 Bytes
d77636f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f43f058
 
 
d77636f
 
 
 
f43f058
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d77636f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import torch
import gradio as gr
import matplotlib.pyplot as plt
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity


model = SentenceTransformer('clip-ViT-B-32')



def predict(im1, im2):
  embeding = model.encode([im1, im2])
  sim = cosine_similarity(embeding)
  sim = sim[0][1]
  if sim > 0.78: # THRESHOLD HERE
    return sim, "SAME PERSON, UNLOCK PHONE"
  else:
    return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"



import gradio as gr


title = 'Face ID'
description = 'This model detects the similarity between two images and passes a command!'


article = """
            Upload and Image from your Device or Make use of your webcam 
          """

img_upload = gr.Interface(
    fn=predict, 
    inputs= [gr.Image(type="pil", source="upload"), 
             gr.Image(type="pil", source="upload")], 
    outputs= [gr.Number(label="Similarity"),
              gr.Textbox(label="Message")],
    title=title,
    description=description,
    article=article
    )

webcam_upload = 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")],
    title=title,
    description=description,
    article=article,
    )

face_id = gr.TabbedInterface(
    [img_upload, webcam_upload], 
    ["Upload-Image", "Use Webcam"])

face_id.launch(debug=True)