Skip to main content

DeepFake Detection

Deepfake Detection (On-Premises) identifies AI-generated or manipulated faces to prevent fraud and digital impersonation. All detection runs locally on your servers, ensuring that sensitive data never leaves your protected environment and helping to safeguard high-security operations.

Prerequisites

Below are the essential prerequisites to ensure the seamless operation of the Facia services:

RequirementSpecification
OSUbuntu 22.04
CPU16 Core 32 Threads
RAM32GB
Disk500GB
ServerFreshly installed and upgraded
DockerDocker installed
DockerEnsure that the latest version of Docker is installed.
NetworkPlease ensure that your Docker network and all Facia-related Docker containers have active internet access to successfully pull images or resources from AWS.
ContainersRemove any previously running containers
note

If you did not setup docker ECR then please follow below steps to login


Install and Configure AWS Account:

The installation of aws-cli can be done using the following command, please run the commands in the following order as it is.

note

If you are not using the internet in your environment then you might need to enable it temporarily to fetch the registries.


sudo apt update
sudo apt install awscli
aws --version
aws configure

Once the above commands are executed successfully then, we need to enter the id and the secret key during the AWS cli configuration.

You will be prompted to enter the Client ID, Secret Token, and AWS Region.

Please copy and paste these credentials from the On-Prem Keys section available on the Merchant Portal in Settings, After Login/Signup.

Input the required values as follows:

  • Client ID
  • Secret Token
  • AWS Region

When prompted with: Default output format [None]: Simply press the Enter key to continue without selecting any output format. Make sure to enter the credentials accurately to ensure a successful configuration.

Sample Response:

root@root:~# aws configure
Access Key ID [None]: your_access_id
AWS Secret Access Key [None]: your_secret_key
Default region name [None]: your_region_name
Default output format [None]:

Now you will have the aws cli configured in your server and good to start builds pulling from the Elastic Container Registry (ECR)

aws configure list

Docker Login to AWS ECR

To access Docker images stored in AWS Elastic Container Registry (ECR), run the following command:

aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 084864413923.dkr.ecr.eu-north-1.amazonaws.com

Setting up the Updated Docker Images from AWS ECR Registry

Pulling the updated images from AWS ECR Registry:

docker pull 084864413923.dkr.ecr.eu-north-1.amazonaws.com/deepfake_detection:hash_id
docker pull 084864413923.dkr.ecr.eu-north-1.amazonaws.com/cache:latest

Run Containers

  1. To run the FACIA application on a different IP address and port, modify the -p flag in the docker run command for ml_services_container. (Optional)
  2. Create a Docker network named facia-network and run the containers with the following commands:

Note: If you have already created the facia-network you can ignore the following step.

docker network create facia-network
docker run -d --name mongodb_local_container \
-e USER=mongoAdmin \
-e PASS=TBbuaxROrspF8K6ugQJ29s8ZMqc \
--network=facia-network \
084864413923.dkr.ecr.eu-north-1.amazonaws.com/cache:latest
docker run -d --name ml_services_container \
--network=facia-network \
-p 127.0.0.1:5001:5001 \
--link mongodb_local_container:mongodb-local \
084864413923.dkr.ecr.eu-north-1.amazonaws.com/deepfake_detection:hash_id

Wait for Initialization

Allow 5-10 minutes for the services to initialize before proceeding.

curl localhost:5001/status_check

if the response is returned as "Service is Live" Then we are good to go with start putting the requests OR you need to wait till its ready.


API Reference

1. Status Check

  • Method: GET
  • URL: /status_check
  • Response:
    • Service is Live. (if the API is operational)
    • Service is Not Live. Please wait for 5 to 10 minutes if it still does not work then restart this build. (Incase the API is not ready)
note

Images must be in PNG, JPG, or JPEG format.

2. User Authentication and Processing:

  • Method: POST
  • URL: /liveness
  • Content-Type: application/json
  • Request Body:

Please Login/Signup to your Facia account in order to get the Hash_id, so you can use docker. Once logged in, you can retrieve the Hash ID from this URL in settings.

{
"hash_id": "hash_id",
"selfie_image": "base64_encoded_image(str)"
}

Server Response:

{
"deepfake_result": {
"deepfake_score": 0.2332232322,
"is_deepfake": 0,
"message": "Provided image is not deepfake!"
},
"status": "Success"
}

Interpretation

  • is_deepfake: 0 (No spoof attack detected ), 1 (Spoof attack detected)
  • deepfake_score: Deepfake score

Use Cases

  • Original Image:
{
"deepfake_result": {
"deepfake_score": 0.2332232322,
"is_deepfake": 0,
"message": "Provided image is not deepfake!"
},
"status": "Success"
}
  • Spoofed Attack:
{
"deepfake_result": {
"deepfake_score": 0.90823823,
"is_deepfake": 1,
"message": "Provided image is deepfake!"
},
"status": "Success"
}
  • Corrupted Image:
{
"error": "Invalid or corrupt selfie image.Images must be in PNG, JPG, or JPEG format"
}

Testing Script in Python:

Note: You need to add the value of the variable within the key “image_path” as per your business needs.

import requests
import base64
import mimetypes
import json
# Your endpoint URL
url = "http://127.0.0.1:5001/liveness"
hash_id = "sdqwdsqwsdqwsq"
def encode_image_with_mime(image_path):
"""
Reads an image file, encodes it in base64 with a validation string, and includes the mime type.
"""
mime_type, _ = mimetypes.guess_type(image_path) # Get MIME type based on the file extension
if not mime_type:
raise ValueError(f"Could not determine MIME type for {image_path}")

with open(image_path, "rb") as img_file:
base64_string = f"data:{mime_type};base64,{base64.b64encode(img_file.read()).decode('utf-8')}"
return base64_string

# Encode selfie image with validation string
selfie_image_base64 = encode_image_with_mime(image1_path)
data = {
"hash_id": hash_id,
"selfie_image": selfie_image_base64 # Use the base64-encoded image string

}
r = requests.post("http://127.0.0.1:5001/liveness", json=json_data)
print(f"Response Code: {r.status_code}")
print(json.loads(r.text))