Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import face_recognition
|
3 |
+
|
4 |
+
|
5 |
+
def run_verification(verification_image, input_image):
|
6 |
+
temp = face_recognition.face_encodings(verification_image)
|
7 |
+
if len(temp) == 1:
|
8 |
+
verification_encoding = face_recognition.face_encodings(verification_image)[0]
|
9 |
+
elif len(temp)>1:
|
10 |
+
return 'Multiple faces detected in verification image β. Verification Image must have a single face'
|
11 |
+
else:
|
12 |
+
return 'No face detected in verification image β. Verification Image must have a single face'
|
13 |
+
|
14 |
+
temp = face_recognition.face_encodings(input_image)
|
15 |
+
if len(temp) == 1:
|
16 |
+
input_encoding = face_recognition.face_encodings(input_image)[0]
|
17 |
+
multiple_people=False
|
18 |
+
elif len(temp)>1:
|
19 |
+
input_encoding = face_recognition.face_encodings(input_image)[0]
|
20 |
+
multiple_people=True
|
21 |
+
else:
|
22 |
+
return 'No face detected in Input Image.'
|
23 |
+
|
24 |
+
results = face_recognition.compare_faces([verification_encoding], input_encoding)
|
25 |
+
|
26 |
+
if results[0]==True and not multiple_people:
|
27 |
+
return 'Facial Verification Successful β
. Both pictures contain the same person'
|
28 |
+
elif results[0]==True and multiple_people:
|
29 |
+
return 'Facial Verification Successful β
. Both pictures contain the same person. Input Image contains multiple faces.'
|
30 |
+
else:
|
31 |
+
return 'Facial Verification Failed β. Both pictures contain different persons'
|
32 |
+
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("# FaceMatch: A Zero Shot Facial Recognition App")
|
35 |
+
gr.Markdown("FaceMatch is a cutting-edge facial recognition application that allows users to compare two images to determine if they depict the same person or not. Unlike traditional facial recognition systems that require a database of known faces, FaceMatch utilizes zero-shot facial recognition technology, which means it can recognize individuals without any prior training using just a single anchor image.")
|
36 |
+
gr.Markdown('''
|
37 |
+
Steps to Run:
|
38 |
+
1. Upload your image as a reference image.
|
39 |
+
2. Upload the input image on which you want to run facial recognition.
|
40 |
+
3. Click "Run Facial Recognition" to initiate the process.
|
41 |
+
4. View the verification result.
|
42 |
+
''')
|
43 |
+
gr.Info('Test')
|
44 |
+
with gr.Row():
|
45 |
+
verification_image = gr.Image(label='Reference Image')
|
46 |
+
input_image = gr.Image(label = 'Input Image')
|
47 |
+
verify_button = gr.Button(value="Run Facial Recognition")
|
48 |
+
output_textbox = gr.Textbox(value="", label="Verification Result")
|
49 |
+
verify_button.click(run_verification, inputs=[verification_image, input_image], outputs=[output_textbox])
|
50 |
+
# upload_button.upload(upload_file, upload_button, file_output)
|
51 |
+
|
52 |
+
demo.launch()
|