File size: 5,159 Bytes
901e379
 
 
 
 
 
 
 
 
 
68df1ee
 
4382ea6
c00995a
 
5143658
c00995a
 
 
 
 
 
5143658
c00995a
 
 
 
 
 
5143658
901e379
947d84d
68df1ee
 
4382ea6
947d84d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
901e379
 
 
77fe87f
 
 
 
 
 
901e379
77fe87f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
901e379
 
 
 
 
 
f61c0c0
901e379
 
 
 
f61c0c0
901e379
 
 
 
 
 
947d84d
 
 
 
 
 
 
 
 
 
 
77fe87f
 
 
 
901e379
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sys
import os
import io
import base64
import json
import gradio as gr
import requests


def face_recognition_on_file(file1, file2):
    
    backend_url = os.getenv('BACKEND_URL')
    url = f"{backend_url}/face_recognition"
    try:
        files = {'file1': open(file1, 'rb'), 'file2': open(file2, 'rb')}

        r = requests.post(url=url, files=files)
        r.raise_for_status()  # Raise an exception for bad status codes
    except requests.RequestException as e:
        raise gr.Error(f"Error occurred: {str(e)}")
    except IOError:
        raise gr.Error("Please select valid image files!")

    try:
        response = r.json()
        print(response)
        return response
    except json.JSONDecodeError:
        raise gr.Error("Invalid response from server")


def liveness_detection_on_file(file):

    backend_url = os.getenv('BACKEND_URL')
    url = f"{backend_url}/check_liveness"
    try:
        files = {'file': open(file, 'rb')}
        r = requests.post(url=url, files=files)
        r.raise_for_status()  # Raise an exception for bad status codes
    except requests.RequestException as e:
        raise gr.Error(f"Error occurred: {str(e)}")
    
    try:
        response = r.json()
        print(response)
        return response
    except json.JSONDecodeError:
        raise gr.Error("Invalid response from server")


with gr.Blocks() as demo:
    gr.Markdown(
        """
        <a href="https://faceplugin.com" style="display: flex; align-items: center;">
            <img src="https://faceplugin.com/wp-content/uploads/2024/02/Square-png-file_2-1.png" style="width: 8%; margin-right: 15px;"/>
            <div>
                <p style="font-size: 24px; font-weight: bold; margin: 0;">FacePlugIn Ltd</p>
            </div>
        </a>

        ## Company Overview

        FacePlugin Ltd is a pioneering company at the forefront of innovative solutions in the realm of facial recognition technology and computer vision. Established with a commitment to revolutionize security and authentication processes, FacePlugin specializes in cutting-edge solutions including face liveness detection, ID card recognition, face recognition, biometric authentication, and e-KYC (Electronic Know Your Customer) solutions.


        <h2>List of our Products</h2>

        * **[FaceRecognition-LivenessDetection-Android](https://github.com/Faceplugin-ltd/FaceRecognition-LivenessDetection-Android)**
        * **[FaceRecognition-LivenessDetection-iOS](https://github.com/Faceplugin-ltd/FaceRecognition-LivenessDetection-iOS)**
        * **[FaceRecognition-LivenessDetection-Javascript](https://github.com/Faceplugin-ltd/FaceRecognition-LivenessDetection-Javascript)**
        * **[FaceLivenessDetection-Docker](https://github.com/Faceplugin-ltd/FaceLivenessDetection-Docker)**


        ## Contact
        <div style="display: flex; align-items: center;">
            <a target="_blank" href="mailto:[email protected]"><img src="https://img.shields.io/badge/[email protected]?logo=gmail " alt="faceplugin.com"></a>&nbsp;&nbsp;
            <a target="_blank" href="https://t.me/faceplugin"><img src="https://img.shields.io/badge/[email protected]?logo=telegram " alt="faceplugin.com"></a>&nbsp;&nbsp;
            <a target="_blank" href="https://wa.me/+14422295661"><img src="https://img.shields.io/badge/whatsapp-faceplugin-blue.svg?logo=whatsapp " alt="faceplugin.com">
        </div>
        """
    )

    with gr.TabItem("Face Recognition"):
        with gr.Row():
            with gr.Column():
                first_input = gr.Image(type='filepath')
                gr.Examples(['images/rec_7.jpg', 'images/rec_1.jpg', 'images/9.png', 'images/rec_3.jpg'],
                            inputs=first_input)
                start_button = gr.Button("Run")
            with gr.Column():
                second_input = gr.Image(type='filepath')
                gr.Examples(['images/rec_8.jpg', 'images/rec_2.jpg', 'images/10.jpg', 'images/rec_4.jpg'],
                            inputs=second_input)

            with gr.Column():
                app_output = [gr.JSON()]

        start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
    with gr.TabItem("Face Liveness Detection"):
        with gr.Row():
            with gr.Column():
                app_input = gr.Image(type='filepath')
                gr.Examples(['images/4.jpg', 'images/1.png', 'images/2.png', 'images/3.png'],
                            inputs=app_input)
                start_button = gr.Button("Run")
            with gr.Column():
                app_output = [gr.JSON()]

        start_button.click(liveness_detection_on_file, inputs=app_input, outputs=app_output)


    gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFacePlugin-Ltd%2FFacePlugin-Face-Recognition-SDK&labelColor=%23697689&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
    
demo.queue().launch(share=True)