File size: 1,762 Bytes
2ded60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43defda
899fad9
 
 
 
d17dbef
2ded60b
 
 
 
 
 
 
 
 
 
 
022ddc9
2ded60b
c504e2f
42da2e7
022ddc9
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
import gradio as gr
import requests
import json

def face_liveness(frame):
    url = "http://127.0.0.1:8000/api/liveness"
    files = None
    if frame is None:
        return ['', None]

    files = {'image': open(frame, 'rb')}
    r = requests.post(url=url, files=files)
    return r.json()

with gr.Blocks() as demo:
    gr.Markdown(
        """
    # Face Liveness Detection
    Get your own Face Liveness Detection Server by duplicating this space.<br/>
        Or run on your own machine using docker.<br/>
    ```docker run -it -p 7860:7860 --platform=linux/amd64 \
	-e LICENSE_KEY="YOUR_VALUE_HERE" \
	registry.hf.space/faceonlive-face-liveness-detection-sdk:latest ```<br/><br/>
    Contact us at https://faceonlive.com for issues and support.<br/>
    """
    )
    with gr.Row():
        with gr.Column(scale=5):
            image_input = gr.Image(type='filepath')
            gr.Examples(['gradio/examples/1.jpg', 'gradio/examples/2.jpg', 'gradio/examples/3.jpg', 'gradio/examples/4.jpg'], 
                            inputs=image_input)
            face_liveness_button = gr.Button("Check Liveness")
        with gr.Column(scale=5):
            liveness_result_output = gr.JSON()
    
    face_liveness_button.click(face_liveness, inputs=image_input, outputs=liveness_result_output, api_name=False)

    gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Liveness-Detection-SDK"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FFace-Liveness-Detection-SDK&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')

demo.queue(api_open=False).launch(server_name="0.0.0.0", server_port=7860, show_api=False)