Skip to content
Snippets Groups Projects
Joohyun Park's avatar
Joohyun Park authored
ab253aae
History

Deepfake Detection Project FALL 2024 CS 4664 CAPSTONE

Joohyun Park Jay Gardner Aidan Adams Ethan Wong

This repository contains a Deepfake Detection system consisting of a Next.js frontend and a Flask backend. The project leverages Docker containers for deployment and includes functionality to upload videos, process them for deepfake analysis, and return results.

Table of Contents

Overview

This project provides a web-based platform for users to upload videos and analyze them for deepfake content using a pre-trained machine learning model. Key components:

  1. Frontend (Next.js):
    • User interface for uploading videos.
    • Displays results of the deepfake analysis.
  2. Backend (Flask):
    • Processes uploaded videos.
    • Runs the deepfake detection model.
  3. AWS S3 Integration:
    • Stores uploaded videos temporarily for processing.
    • Generates pre-signed URLs for secure access.

Folder Structure

├── src
│   ├── app
│   │   ├── page.tsx
│   │   ├── layout.tsx
│   │   ├── app.py
│   │   ├── svm_model.joblib
│   │   └── ...
│   ├── pages
│   │   ├── api
│   │   │   ├── uploadToS3.ts
│   │   │   ├── analyzeVideo.ts
│   │   │   ├── deleteVideo.ts
│   │   │   ├── swagger.json.ts
│   │   ├── api-docs.tsx
├── index.ts
├── swagger.ts
├── Dockerfile
├── Dockerfile.dev
├── Dockerfile.backend
├── README.md
├── ...

Dockerfiles

Dockerfile (Production Frontend)

  • Builds a production-ready Next.js frontend.
  • Includes:
    • Two-stage build process.
    • Optimized for performance.
  • Exposes port 80.

Dockerfile.dev (Development Frontend)

  • Configures a development environment for the frontend.
  • Includes:
    • Hot reloading using npm run dev.
  • Exposes port 3000.

Dockerfile.backend (Flask Backend)

  • Builds and runs the Flask backend.
  • Includes:
    • Python dependencies for the deepfake detection model.
    • OpenCV and MediaPipe for video processing.
  • Exposes port 5000.

Setup Instructions

Prerequisites

  • Docker Installed: Ensure Docker is installed and running on your local machine.
  • Kubernetes ConfigMap for Deployment: Create a Kubernetes ConfigMap for managing environment variables for your public deployment. This includes API endpoints, AWS credentials, and other configurations.
  • AWS S3 Bucket: Set up an AWS S3 bucket to store uploaded video files temporarily. Ensure the bucket is configured with proper access policies and credentials.

Building and Pushing Docker Images

  • Development Workflow for Locally below this section.
  1. Log into VT docker registry
    docker login container.cs.vt.edu
  2. Frontend (Production):
    docker build -f Dockerfile -t container.cs.vt.edu/<your_pid>/<project-name>.prod:latest .
    docker push container.cs.vt.edu/<your_pid>/<project-name>.prod:latest
  3. Frontend (Development):
    docker build -f Dockerfile.dev -t container.cs.vt.edu/<your_pid>/<project-name>.dev:latest .
    docker push container.cs.vt.edu/<your_pid>/<project-name>.dev:latest
  4. Backend:
    docker build -f Dockerfile.backend -t container.cs.vt.edu/<your_pid>/<project-name>.backend:latest .
    docker push container.cs.vt.edu/<your_pid>/<project-name>.backend:latest

Development Workflow for Locally

  1. Clone the repository.
  2. .env.local file with the following variables:
    AWS_ACCESS_KEY_ID=<your-access-key>
    AWS_SECRET_ACCESS_KEY=<your-secret-key>
    AWS_REGION=<your-region>
    AWS_BUCKET_NAME=<your-bucket-name>
    FLASK_API_ENDPOINT=<backend-api-url>
  3. Install dependencies:
    npm install
  4. Run the frontend in development mode:
    npm run dev
  5. Build the backend image and run it locally:
    docker build -f Dockerfile.backend -t my-app-backend .
    docker run -p 5000:5000 my-app-backend

Deployment Workflow

  1. Push Docker images to your container registry (e.g., AWS ECR, DockerHub).
  2. Configure Kubernetes or another orchestrator to manage containers.
  3. Deploy using Kubernetes Ingress for routing traffic:
    • / -> Frontend (port 80)
    • /api/flask -> Backend (port 5000)

API Endpoints

The API documentation for this project is available through Swagger. You can access it at:

Swagger UI

It includes details about:

  • /api/uploadToS3: Uploads video files to AWS S3.
  • /api/analyzeVideo: Analyzes a video for deepfake detection.
  • /api/deleteVideo: Deletes an uploaded video from AWS S3.

Refer to Swagger UI for detailed request/response formats and examples.

/api/uploadToS3

  • Method: POST
  • Description: Uploads video files to AWS S3.
  • Request Body:
    {
    "fileName": "example.mp4",
    "fileContentType": "video/mp4",
    "fileData": "<base64-encoded-data>"
    }
  • Response:
    {
    "message": "Upload successful",
    "url": "https://<bucket-name>.s3.<region>.amazonaws.com/<fileName>"
    }

/api/analyzeVideo

  • Method: POST
  • Description: Sends video pre-signed URL to the Flask backend for analysis. app.py will handle
  • Request Body:
    {
    "video_url": "https://<bucket-name>.s3.<region>.amazonaws.com/<fileName>"
    }
  • Response:
    {
    "total_frames": 100,
    "deepfake_frames": 20,
    "deepfake_percentage": 20
    }

/api/deleteVideo

  • Method: POST
  • Description: Deletes the uploaded video from AWS S3.
  • Request Body:
    {
    "fileName": "example.mp4"
    }
  • Response:
    {
    "message": "Object deleted successfully"
    }