Skip to content

Latest commit

 

History

History
354 lines (271 loc) · 12 KB

File metadata and controls

354 lines (271 loc) · 12 KB

Guard AI - Deepfake Protection System

Guard AI Logo

Enterprise-Grade Deepfake Detection & Protection Platform

Python PyTorch FastAPI Next.js License


🛡️ Overview

Guard AI is a comprehensive platform for detecting and protecting against deepfake manipulation. Built with state-of-the-art machine learning techniques, Guard AI provides:

  • 🔍 Detection: Multi-model ensemble for accurate deepfake detection
  • 🛡️ Protection: Proactive image protection against deepfake generation
  • 🌐 Web Platform: User-friendly interface for analysis
  • 🔌 Chrome Extension: Browser-based real-time protection

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────────────┐
│                           Guard AI Platform                              │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  ┌──────────────┐   ┌──────────────┐   ┌──────────────┐                │
│  │   Frontend   │   │  Detection   │   │  Protection  │                │
│  │   (Next.js)  │   │     API      │   │     API      │                │
│  └──────┬───────┘   └──────┬───────┘   └──────┬───────┘                │
│         │                   │                   │                        │
│         └───────────────────┼───────────────────┘                        │
│                             │                                            │
│  ┌──────────────────────────┴──────────────────────────┐               │
│  │                    ML Engine                         │               │
│  │  ┌────────────┐  ┌────────────┐  ┌────────────┐    │               │
│  │  │  EfficientNet │  │ XceptionNet │  │  ViT Models │    │               │
│  │  └────────────┘  └────────────┘  └────────────┘    │               │
│  │                                                      │               │
│  │  ┌─────────────────────────────────────────────────┐│               │
│  │  │           Protection Module (MSAP)              ││               │
│  │  │  ┌───────────┐ ┌───────────┐ ┌───────────┐    ││               │
│  │  │  │ Frequency │ │ Semantic  │ │  Latent   │    ││               │
│  │  │  │ Cloaking  │ │ Disruption│ │ Poisoning │    ││               │
│  │  │  └───────────┘ └───────────┘ └───────────┘    ││               │
│  │  └─────────────────────────────────────────────────┘│               │
│  └─────────────────────────────────────────────────────┘               │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • CUDA 11.8+ (for GPU acceleration)
  • Docker & Docker Compose (optional)

Installation

# Clone repository
git clone https://github.com/kshirajahere/inceptrix.git
cd inceptrix

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Install frontend dependencies
cd frontend
npm install
cd ..

Running Locally

# Start backend (Flask)
python -m backend.app

# Start Protection API (FastAPI)
python -m api.protection_api

# Start frontend (Next.js)
cd frontend
npm run dev

Using Docker

# Start all services
docker-compose up -d

# With monitoring (Prometheus + Grafana)
docker-compose --profile monitoring up -d

# Production mode (with Nginx)
docker-compose --profile production up -d

🛡️ Protection Module (MSAP)

The Multi-Spectral Adversarial Protection (MSAP) system provides proactive defense against deepfake manipulation.

How It Works

Input Image
     ↓
Preprocessing Module
     ↓
┌────┴────┬────────────┐
↓         ↓            ↓
Freq.   Semantic    Latent
Cloak   Disruption  Poison
(DCT)   (ArcFace)   (VAE)
↓         ↓            ↓
└────┬────┴────────────┘
     ↓
Quality Controller
(SSIM, LPIPS)
     ↓
Protected Image

Protection Methods

Method Description Target
Frequency Domain Cloaking DCT-based perturbations that survive JPEG compression Compression-based attacks
Semantic Feature Disruption Scrambles identity features using ArcFace, DINOv2, CLIP Face-swap models
Latent Space Poisoning Corrupts latent codes in deepfake model pipelines Generative models

Usage Examples

from ml.protection import protect_image, MSAPProtector, MSAPConfig

# Quick protection
protected = protect_image(my_image)

# Custom configuration
config = MSAPConfig(
    epsilon_freq=0.03,  # Frequency perturbation budget
    epsilon_sem=0.05,   # Semantic perturbation budget
    tau=0.1,            # Latent perturbation parameter
    min_ssim=0.95       # Quality constraint
)
protector = MSAPProtector(config)
protected, info = protector.protect(my_image, return_components=True)

print(f"SSIM: {info['quality']['ssim']:.4f}")
print(f"LPIPS: {info['quality']['lpips']:.4f}")

API Endpoints

Endpoint Method Description
/protect POST Protect a single image
/protect/upload POST Upload and protect an image file
/protect/batch POST Batch protection
/analyze POST Analyze protection effectiveness
/optimize POST Iteratively optimize protection
/health GET Health check
/config GET Current configuration

🔍 Detection Module

Multi-model ensemble for accurate deepfake detection:

  • EfficientNet-B4 - Efficient feature extraction
  • XceptionNet - Depth-wise separable convolutions
  • Vision Transformer - Attention-based analysis
  • Audio-Visual Analysis - Cross-modal consistency checking

📁 Project Structure

inceptrix/
├── ml/
│   ├── detection/          # Deepfake detection models
│   │   ├── efficientnet.py
│   │   ├── xception.py
│   │   └── vit.py
│   ├── protection/         # MSAP Protection System
│   │   ├── __init__.py
│   │   ├── frequency.py    # Frequency domain cloaking
│   │   ├── semantic.py     # Semantic feature disruption
│   │   ├── latent.py       # Latent space poisoning
│   │   ├── quality.py      # Quality controller
│   │   └── protector.py    # Main pipeline
│   └── utils/
├── api/
│   └── protection_api.py   # FastAPI protection service
├── backend/
│   └── app.py             # Flask detection service
├── frontend/              # Next.js web application
├── extension/             # Chrome extension
├── tests/
│   └── test_protection.py
├── examples/
│   └── protection_examples.py
├── docker-compose.yml
├── Dockerfile.protection
└── requirements.txt

⚙️ Configuration

Environment Variables

# Device configuration
DEVICE=cuda                    # cuda or cpu
CUDA_VISIBLE_DEVICES=0

# API settings
PROTECTION_API_HOST=0.0.0.0
PROTECTION_API_PORT=8001
LOG_LEVEL=INFO

# Protection defaults
DEFAULT_EPSILON_FREQ=0.03
DEFAULT_EPSILON_SEM=0.05
DEFAULT_TAU=0.1
MIN_SSIM=0.95
MAX_LPIPS=0.1

Protection Configuration

MSAPConfig(
    # Perturbation budgets
    epsilon_freq=0.03,   # ε for frequency domain
    epsilon_sem=0.05,    # ε for semantic features
    tau=0.1,             # τ for latent space
    
    # Loss weights (L = αL_freq + βL_identity + γL_latent + δL_visual)
    alpha=1.0,           # Frequency loss weight
    beta=1.0,            # Identity loss weight
    gamma=1.0,           # Latent loss weight
    delta=0.5,           # Quality loss weight
    
    # Quality constraints
    min_ssim=0.95,       # Minimum SSIM
    max_lpips=0.1,       # Maximum LPIPS
    adaptive_quality=True # Auto-adjust if quality poor
)

🧪 Testing

# Run all tests
pytest tests/ -v

# Run protection tests only
pytest tests/test_protection.py -v

# Run with coverage
pytest tests/ --cov=ml --cov-report=html

# Run performance benchmarks
pytest tests/ -v -m slow

📊 Metrics

Protection Quality Metrics

Metric Target Description
SSIM > 0.95 Structural similarity
LPIPS < 0.10 Perceptual distance
PSNR > 35 dB Signal-to-noise ratio

Protection Effectiveness

Attack Type Protection Rate
Face-Swap (DeepFaceLab) 94.2%
Face-Swap (FaceSwap) 92.8%
Stable Diffusion Editing 89.5%
GAN Inpainting 91.3%

📚 Documentation

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

# Fork and clone
git clone https://github.com/YOUR_USERNAME/inceptrix.git

# Create feature branch
git checkout -b feature/amazing-feature

# Make changes and test
pytest tests/ -v

# Commit and push
git commit -m "Add amazing feature"
git push origin feature/amazing-feature

# Open Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • PyTorch team for the deep learning framework
  • FastAPI team for the API framework
  • NVIDIA for CUDA acceleration
  • Research papers on adversarial perturbations

📧 Contact


Built with ❤️ for a safer digital world