Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| #import cv2 | |
| from deepface import DeepFace | |
| # Define functions for each functionality | |
| def verify_images(image1, image2): | |
| result = DeepFace.verify(image1, image2) | |
| return result | |
| def identify_image(image, database): | |
| #results = [] | |
| #for db_image in database: | |
| result = DeepFace.find(image, database) | |
| final = result[0]['identity'].tolist() | |
| #if result: | |
| # results.append(db_image) | |
| return final | |
| '''#def real_time_face_identification(video_source): | |
| cap = cv2.VideoCapture(video_source) | |
| while True: | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| # Perform face identification (example code) | |
| faces = DeepFace.detectFace(frame) | |
| # Display results | |
| cv2.imshow('Face Identification', frame) | |
| if cv2.waitKey(1) & 0xFF == ord('q'): | |
| break | |
| cap.release() | |
| cv2.destroyAllWindows()''' | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn= | |
| verify_images | |
| # identify_image | |
| #real_time_face_identification | |
| , | |
| inputs=[ | |
| gr.Image(type="filepath"), gr.Image(type="filepath") | |
| #gr.Image(type="filepath"), gr.Textbox(label="Paste database path here") | |
| #gr.Video() | |
| ], | |
| outputs=[ | |
| gr.Textbox(label="Verification Result") | |
| #gr.Gallery(label="Identified Images"), | |
| #None | |
| ] | |
| ) | |
| iface2 = gr.Interface( | |
| fn= | |
| identify_image | |
| , | |
| inputs=[ | |
| gr.Image(type="filepath"), gr.Textbox(label="Paste database path here") | |
| ], | |
| outputs=[ | |
| gr.Gallery(label="Identified Images" , show_label=False, elem_id="gallery" | |
| , columns=[3], rows=[2], object_fit="contain", height="auto") | |
| ] ) | |
| demo = gr.TabbedInterface([iface, iface2], ["Face Verification", "Face Identification"]) | |
| demo.launch() | |