File size: 1,904 Bytes
7e38b61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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()