Dwight18/Facial_recognition_test
0
1import gradio as gr2import face_recognition3 4 5def 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=False18 elif len(temp)>1:19 input_encoding = face_recognition.face_encodings(input_image)[0]20 multiple_people=True21 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 33with 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('''37Steps to Run:381. Upload your image as a reference image.392. Upload the input image on which you want to run facial recognition.403. Click "Run Facial Recognition" to initiate the process.414. 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 52demo.launch()