File size: 2,637 Bytes
61bfaf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import face_recognition


def run_verification(verification_image, input_image):
    temp = face_recognition.face_encodings(verification_image)
    if len(temp) == 1:
        verification_encoding = face_recognition.face_encodings(verification_image)[0]
    elif len(temp)>1:
        return 'Multiple faces detected in verification image ❌. Verification Image must have a single face'
    else:
        return 'No face detected in verification image ❌. Verification Image must have a single face'
    
    temp = face_recognition.face_encodings(input_image)
    if len(temp) == 1:
        input_encoding = face_recognition.face_encodings(input_image)[0]
        multiple_people=False
    elif len(temp)>1:
        input_encoding = face_recognition.face_encodings(input_image)[0]
        multiple_people=True
    else:
        return 'No face detected in Input Image.'

    results = face_recognition.compare_faces([verification_encoding], input_encoding)
    
    if results[0]==True and not multiple_people:
        return 'Facial Verification Successful βœ…. Both pictures contain the same person'
    elif results[0]==True and multiple_people:
        return 'Facial Verification Successful βœ…. Both pictures contain the same person. Input Image contains multiple faces.'
    else:
        return 'Facial Verification Failed ❌. Both pictures contain different persons'

with gr.Blocks() as demo:
    gr.Markdown("# FaceMatch: A Zero Shot Facial Recognition App")
    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.")
    gr.Markdown('''
Steps to Run:
1. Upload your image as a reference image.
2. Upload the input image on which you want to run facial recognition.
3. Click "Run Facial Recognition" to initiate the process.
4. View the verification result.
''')
    gr.Info('Test')
    with gr.Row():
        verification_image = gr.Image(label='Reference Image')
        input_image = gr.Image(label = 'Input Image')
    verify_button = gr.Button(value="Run Facial Recognition")
    output_textbox = gr.Textbox(value="", label="Verification Result")
    verify_button.click(run_verification, inputs=[verification_image, input_image], outputs=[output_textbox])
    # upload_button.upload(upload_file, upload_button, file_output)

demo.launch()