|
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) |