Skip to content

A comprehensive web application for detecting deepfakes and AI-generated images using a multi-layer authentication system. Protect yourself from impersonation and unauthorized use of your likeness.

Notifications You must be signed in to change notification settings

blackscythe123/faceguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ FaceGuard - Digital Dignity Shield

A comprehensive web application for detecting deepfakes and AI-generated images using a multi-layer authentication system. Protect yourself from impersonation and unauthorized use of your likeness.

FaceGuard Banner

🌟 Features

Image Protection

  • Invisible Watermarking: Embed robust watermarks using dwtDct method
  • Facial Embedding Storage: 128-dimensional facial feature vectors using Facenet
  • Digital Certificates: JSON certificates with SHA-256 hashes for verification

Multi-Layer Detection

  1. Watermark Detection: Check for FaceGuard protection watermarks
  2. Facial Biometric Matching: Compare against registered user embeddings
  3. Deepfake Analysis: Detect manipulation artifacts and GAN signatures
  4. SynthID Detection: Identify Google Gemini/Imagen generated images

Evidence Reports

  • Professional PDF reports for legal takedown requests
  • Trust score visualization
  • Legal notice templates
  • Complete analysis documentation

🏗️ Architecture

faceguard/
├── backend/               # FastAPI Python backend
│   ├── main.py           # API endpoints
│   ├── models/           # ML models (SynthID, DeepFace, Deepfake)
│   ├── services/         # Business logic
│   ├── database/         # SQLAlchemy models
│   └── utils/            # Helper functions
├── frontend/             # React + TypeScript frontend
│   ├── src/
│   │   ├── components/   # React components
│   │   ├── api/          # API client
│   │   └── types/        # TypeScript definitions
│   └── public/
└── README.md

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Git

Backend Setup

cd faceguard/backend

# Create virtual environment
python -m venv venv

# Activate (Windows)
venv\Scripts\activate

# Activate (macOS/Linux)
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd faceguard/frontend

# Install dependencies
npm install

# Run development server
npm run dev

Access the Application

📡 API Endpoints

Health Check

GET /api/health

Protect Image

POST /api/protect
Content-Type: multipart/form-data

image: File
email: string

Response:

{
  "success": true,
  "user_id": "uuid",
  "protected_image_url": "/downloads/protected_xxx.png",
  "certificate": {
    "user_id": "uuid",
    "original_hash": "sha256...",
    "embedding_stored": true,
    "watermark_key": "derived_key...",
    "timestamp": "2026-01-22T10:30:00Z"
  }
}

Analyze Image

POST /api/analyze
Content-Type: multipart/form-data

image: File
email: string (optional)

Response:

{
  "success": true,
  "analysis_id": "uuid",
  "results": {
    "watermark": {
      "present": false,
      "owner_id": null
    },
    "face_match": {
      "similarity": 0.87,
      "matched_user": "user@example.com",
      "is_match": true
    },
    "deepfake": {
      "confidence": 0.92,
      "likely_fake": true,
      "model_used": "HeuristicAnalyzer"
    },
    "synthid": {
      "is_synthetic": true,
      "confidence": 0.94,
      "source": "gemini"
    },
    "trust_score": 0,
    "verdict": "HIGHLY SUSPICIOUS"
  },
  "evidence_report_url": "/api/reports/uuid.pdf"
}

Download Evidence Report

GET /api/reports/{analysis_id}.pdf

🔬 Detection Layers Explained

Layer 1: Watermark Detection

  • Uses invisible-watermark library with dwtDct encoding
  • Survives JPEG compression and screenshots (~80% survival rate)
  • Payload: USER:{user_id}|TIME:{timestamp}

Layer 2: Facial Biometric Matching

  • DeepFace with Facenet model (128-d vectors)
  • Cosine similarity comparison
  • Threshold: 0.85 for positive match

Layer 3: Deepfake Detection

  • Frequency analysis (FFT for GAN artifacts)
  • Color consistency checks (LAB color space)
  • Texture analysis (Laplacian variance)
  • Edge pattern analysis (Canny edge detection)

Layer 4: SynthID Detection

  • Uses google/synthid-image-detector from Hugging Face
  • Specifically detects Gemini/Imagen generated images
  • Binary classification with confidence score

📊 Trust Score Calculation

def calculate_trust_score(watermark_present, face_similarity, deepfake_conf, synthid_detected):
    score = 100
    if not watermark_present:
        score -= 30
    if face_similarity > 0.85:
        score -= 25
    if deepfake_conf > 0.80:
        score -= 25
    if synthid_detected:
        score -= 20
    return max(0, score)
Score Range Verdict
80-100 LIKELY AUTHENTIC
60-79 UNCERTAIN
40-59 SUSPICIOUS
20-39 LIKELY FAKE
0-19 HIGHLY SUSPICIOUS

🎨 UI Features

  • Dark Mode: Modern dark theme with light mode toggle
  • Drag & Drop: Smooth file upload experience
  • Progress Indicators: Real-time processing status
  • Animated Trust Gauge: Visual score representation
  • Responsive Design: Mobile-friendly layout

🔒 Security Considerations

  • All facial embeddings are stored as encrypted blobs
  • Watermark keys are derived from hashed emails
  • No raw images are stored after processing
  • CORS configured for localhost only in development

📦 Dependencies

Backend

  • FastAPI + Uvicorn
  • SQLAlchemy (SQLite)
  • invisible-watermark
  • DeepFace + TensorFlow
  • Transformers + PyTorch
  • ReportLab (PDF generation)
  • OpenCV + Pillow

Frontend

  • React 18 + TypeScript
  • Tailwind CSS
  • Axios
  • React Dropzone
  • Recharts
  • Lucide Icons

🧪 Testing

Test Watermark

# Protect an image
response = requests.post('/api/protect', files={'image': img}, data={'email': 'test@example.com'})

# Download and analyze
response = requests.post('/api/analyze', files={'image': protected_img})
assert response.json()['results']['watermark']['present'] == True

Test Face Matching

# Upload photo 1
response1 = requests.post('/api/protect', files={'image': photo1}, data={'email': 'user@example.com'})

# Analyze photo 2 of same person
response2 = requests.post('/api/analyze', files={'image': photo2}, data={'email': 'user@example.com'})
assert response2.json()['results']['face_match']['similarity'] > 0.85

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

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

🙏 Acknowledgments

  • Google's SynthID for AI-generated image detection
  • DeepFace library for facial recognition
  • invisible-watermark for robust watermarking
  • Hugging Face for model hosting

👥 Team

Built with ❤️ for K-Hacks 2026


FaceGuard - Protecting digital dignity against deepfakes and AI impersonation 🛡️

About

A comprehensive web application for detecting deepfakes and AI-generated images using a multi-layer authentication system. Protect yourself from impersonation and unauthorized use of your likeness.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published