ThankGod commited on
Commit
b4db714
1 Parent(s): adba276

Updated from colab

Browse files
Files changed (5) hide show
  1. app.py +55 -0
  2. examples/img1.jpg +0 -0
  3. examples/img2.jpg +0 -0
  4. examples/img3.jpg +0 -0
  5. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ import matplotlib.pyplot as plt
4
+ from sentence_transformers import SentenceTransformer
5
+ from sklearn.metrics.pairwise import cosine_similarity
6
+
7
+ model = SentenceTransformer('clip-ViT-L-14')
8
+
9
+ def predict(im1, im2):
10
+ embeding = model.encode([im1, im2])
11
+ sim = cosine_similarity(embeding)
12
+ sim = sim[0][1]
13
+ if sim > 0.75:
14
+ return sim, "SAME PERSON, UNLOCK PHONE"
15
+ else:
16
+ return sim, "DIFFERENT PEOPLE, DON'T UNLOCK"
17
+
18
+
19
+ title="Face-id Application Demo"
20
+ description = "Upload similar/different images to compare Image similarity for face-id demo"
21
+ article = """
22
+ - Select an image from the examples provided as demo image
23
+ - Click submit button to make Image classification
24
+ - Click clear button to try new Image for classification
25
+ """
26
+
27
+ img_upload = gr.Interface(
28
+ fn=predict,
29
+ inputs= [gr.Image(type="pil", source="upload"),
30
+ gr.Image(type="pil", source="upload")],
31
+ outputs= [gr.Number(label="Similarity"),
32
+ gr.Textbox(label="Message")],
33
+ title=title,
34
+ description=description,
35
+ article=article,
36
+ examples=[['examples/img1.jpg', 'examples/img2.jpg'],
37
+ ['examples/img1.jpg', 'examples/img3.jpg']]
38
+ )
39
+
40
+ webcam_upload = gr.Interface(
41
+ fn=predict,
42
+ inputs= [gr.Image(type="pil", source="webcam"),
43
+ gr.Image(type="pil", source="webcam")],
44
+ outputs= [gr.Number(label="Similarity"),
45
+ gr.Textbox(label="Message")],
46
+ title=title,
47
+ description=description,
48
+ article=article,
49
+ )
50
+
51
+ face_id = gr.TabbedInterface(
52
+ [img_upload, webcam_upload],
53
+ ["Upload-Image", "Use Webcam"])
54
+
55
+ face_id.launch(debug=True)
examples/img1.jpg ADDED
examples/img2.jpg ADDED
examples/img3.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers
3
+ sentence-transformers