# Sample Application

## Docker

Pull the Docker image and run the container:

{% code overflow="wrap" %}

```sh
sudo docker pull recognito/face-liveness_v7:latest
sudo docker run -it -e FL_LICENSE_KEY="XXXXX-XXXXX-XXXXX-XXXXX" -p 8001:8000 -p 7861:7860 recognito/face-liveness_v7:latest [OPTION --gradio(-g), --flask(-f)]
```

{% endcode %}

***

## Installation

### - Download

[**FaceLivenessDetection-Demo(v7).zip**](https://www.dropbox.com/scl/fi/zpcxfkqkvuap2yea4nmrz/FaceLivenessDetection-Demo-v7.zip?rlkey=g3mwq2m4nh65nrq1m80rk3oen\&st=hcxkn59s\&dl=0)

The Demo directory contains the following directories and files:

<table data-header-hidden><thead><tr><th width="206"></th><th></th></tr></thead><tbody><tr><td><strong>dependency\</strong></td><td>Dependency files</td></tr><tr><td><strong>engine\</strong></td><td>SDK engine files</td></tr><tr><td><strong>examples\</strong></td><td>Sample images for face liveness detection</td></tr><tr><td><strong>flask\</strong></td><td>Flask server side demo code</td></tr><tr><td><strong>gradio\</strong></td><td>Gradio demo code</td></tr><tr><td>Dockerfile</td><td>Dockerfile for building a Docker image</td></tr><tr><td>install.sh</td><td>Script for install environment</td></tr><tr><td>license.txt</td><td>License key file</td></tr><tr><td>run_demo.sh</td><td>Script for run demo</td></tr></tbody></table>

### - Install dependencies

Run the `install.sh` script to install dependencies:

```
./install.sh
```

### - Setting Up SDK License Key

* **Online Licensing:** Set the online license key as an environment variable:

{% code overflow="wrap" %}

```sh
export FL_LICENSE_KEY="XXXXX-XXXXX-XXXXX-XXXXX"
```

{% endcode %}

* **Offline Licensing:** Copy the `license.txt` license file to the demo directory.

***

## Test

### - Run Demo

Run the demo script with the desired option:

{% code overflow="wrap" %}

```sh
./run_demo.sh [OPTION --gradio(-g), --flask(-f), --help(-h)]
```

{% endcode %}

<figure><img src="https://3902005046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxiEW2bRNeDz3JZIL41gD%2Fuploads%2FjytHkhInuxGmZjY3Gx5X%2Fliveness_v7-gradio.png?alt=media&#x26;token=81079583-c8f1-4013-9086-db35c060eaf1" alt=""><figcaption></figcaption></figure>

### - Test Flask Server APIs

To test the Flask Server API, you can use [Postman](https://www.postman.com/downloads/). Here are the endpoints for testing:

#### &#x20; <mark style="background-color:blue;">POST</mark> /api/check\_liveness

&#x20; Perform face liveness detection and attribute analysis on an image file

&#x20;   **Parameters**

&#x20;        **image:** image file

&#x20;   **Response**&#x20;

&#x20;        **result:** face liveness, attribute check result

&#x20;        **liveness\_score:** liveness score of detected face

&#x20;        **face\_rect:** face bounding box of detected face

&#x20;        **angles:** Pitch, Yaw, Roll of detected face

#### &#x20; <mark style="background-color:blue;">POST</mark> /api/check\_liveness\_base64

&#x20; Perform face liveness detection and attribute analysis on a base64 image

&#x20;   **Parameters**

&#x20;        **image:** base64 image

&#x20;   **Response**&#x20;

&#x20;        **result:** face liveness, attribute check result

&#x20;        **liveness\_score:** liveness score of detected face

&#x20;        **face\_rect:** face bounding box of detected face

&#x20;        **angles:** Pitch, Yaw, Roll of detected face

<figure><img src="https://3902005046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxiEW2bRNeDz3JZIL41gD%2Fuploads%2FI2xsevfCiRKt2Q8ghfDs%2Fliveness-postman.png?alt=media&#x26;token=cabbe4aa-47de-4f44-a914-8cd42320251b" alt=""><figcaption><p>Postman usage guide for Flask Demo</p></figcaption></figure>

### - Test Gradio

Go to <http://127.0.0.1:7860/> on a web browser.

<figure><img src="https://3902005046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxiEW2bRNeDz3JZIL41gD%2Fuploads%2FfkKBYpRuTWG1w3PbQOmZ%2Ffaceliveness_v7-gradio.png?alt=media&#x26;token=d7792ef6-bcfd-4285-88b7-6779b1ce3c23" alt=""><figcaption><p>Gradio Demo</p></figcaption></figure>
