Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ DeepGuard

Explainable AI for Image Authenticity Detection

DeepGuard Python React TensorFlow FastAPI

Deploy to Render Β Β Β Β  Deploy with Vercel

DeepGuard is an academic-grade full-stack system designed to detect whether an image is Genuine (Real) or AI-Generated (Fake), providing visual evidence of its decision using Grad-CAM class activation mapping. The system features a custom ResNet50 convolutional neural network, a FastAPI backend, and a high-fidelity glassmorphic React frontend.


✨ Key Features

  • Dual-Layer Forensic Pipeline: Combines deep learning classification with EXIF metadata parsing and AIGC signature audits.
  • EXIF & AIGC Metadata Scanner: Automatically parses embedded camera metadata (make, model, software, creation dates) and scans PNG/JPEG text chunks for AI signatures (e.g., Stable Diffusion prompt parameters, Midjourney metadata, and DALL-E tags). AI-detected metadata automatically overrides classification to AI-Generated with 100% confidence.
  • Interactive Heatmap Opacity Blender: An interactive slider overlay in the React UI allows users to dynamically blend and fade the Grad-CAM activation heatmap on top of their uploaded image.
  • Memory-Optimized Cloud Fallback: Features a robust, silent FORCE_MOCK_MODE environment toggle. If enabled (e.g., on Render's 512MB free tier to prevent Out-of-Memory crashes) or if TensorFlow is missing, the backend runs in a fast, lightweight mock mode (~35MB RAM).
  • Premium Glassmorphic Design: Clean typography with Google Font Plus Jakarta Sans, vibrant color states, smooth animations, and fully responsive grid layouts.

πŸ“ Architecture & Flow

                      [ User Uploads Image ]
                                ↓
        [ React Frontend ] (Vite + Plus Jakarta Sans + Axios)
                                ↓ POST /predict
          [ FastAPI Backend ] (CORS Enabled, port 8000)
             /                                      \
            /                                        \
  [ EXIF & AIGC Scanner ]                  [ Deep Learning Classifier ]
 (Pillow metadata scans)                    (ResNet50 Sigmoid Output)
            \                                        /
             \                                      /
       [ Payload Builder ] ──←── [ Grad-CAM Heatmap Generator ]
  { label, confidence, heatmap_b64, metadata }
                                ↓
  [ Frontend Overlay Blender ] (Dynamic alpha slider controls)

πŸ“‚ Project Structure

DeepGuard/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                  # FastAPI server configuration
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   └── predict.py           # POST /predict controller
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ model_service.py     # Model loader & inference wrapper
β”‚   β”‚   β”‚   └── gradcam.py           # Grad-CAM heatmap generator
β”‚   β”‚   └── utils/
β”‚   β”‚       β”œβ”€β”€ image_utils.py       # Image validation & BGR preprocessing
β”‚   β”‚       └── metadata_utils.py    # Pillow-based EXIF and AIGC scanner
β”‚   β”œβ”€β”€ requirements.txt             # Backend dependencies
β”‚   β”œβ”€β”€ test_model.py                # Local model prediction tests
β”‚   β”œβ”€β”€ test_gradcam.py              # Local Grad-CAM heatmap rendering tests
β”‚   └── test_predict.py              # Local API router endpoint tests
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.jsx           # Premium glassmorphic header
β”‚   β”‚   β”‚   β”œβ”€β”€ HeroSection.jsx      # Title & onboarding intro
β”‚   β”‚   β”‚   β”œβ”€β”€ UploadSection.jsx    # Drag-and-drop file uploader
β”‚   β”‚   β”‚   β”œβ”€β”€ ResultsSection.jsx   # Results dashboard with opacity slider
β”‚   β”‚   β”‚   └── Footer.jsx           # Info footer
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js               # Axios client
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ index.css                # Base Tailwind & custom card borders
β”‚   β”‚   └── main.jsx
β”‚   β”œβ”€β”€ index.html                   # HTML template & Jakarta font loading
β”‚   β”œβ”€β”€ package.json                 # Node dependencies
β”‚   β”œβ”€β”€ vite.config.js               # Proxy setup for localhost dev
β”‚   └── vercel.json                  # Vercel SPA rewrites config
β”œβ”€β”€ model/
β”‚   └── deepguard_model.h5           # Model file placeholder
β”œβ”€β”€ training/
β”‚   └── train_model.py               # Complete ResNet50 fine-tuning script
β”œβ”€β”€ render.yaml                      # Render Infrastructure-as-code Blueprint
└── README.md

πŸš€ Local Development Quick Start

Prerequisites

  • Python $\ge$ 3.10 (Tested on Python 3.11.7 and Python 3.14.5)
  • Node.js $\ge$ 18 (Tested on Node.js v24.16.0)

1. Backend Setup

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
.\venv\Scripts\activate
# macOS/Linux:
# source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Start FastAPI server
python -m uvicorn app.main:app --port 8000 --reload

The API docs will be available at http://localhost:8000/docs.

2. Frontend Setup

# Open a new terminal and navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start Vite development server
npm run dev

The React interface will be running at http://localhost:5173. The Vite proxy configuration automatically routes /predict and /health requests to http://localhost:8000.


πŸ‹οΈ Model Training

The training directory includes a transfer learning pipeline based on ResNet50 pre-trained on ImageNet.

cd training

# Train with default settings (expects dataset/real and dataset/ai_generated)
python train_model.py --epochs 15 --batch 32 --lr 0.0001

CLI Options:

  • --dataset: Directory path of dataset (default: ../dataset)
  • --output: Output file path for saving the model (default: ../model/deepguard_model.h5)
  • --epochs: Maximum number of training epochs (default: 15)
  • --lr: Base learning rate (default: 1e-4)
  • --fine_tune_at: Unfreeze base ResNet50 weights starting at this layer index (default: 140)

πŸ”Œ API Reference

Health Check

GET /health

  • Response: {"status": "running"}

Predict Authenticity

POST /predict

  • Request: multipart/form-data with form field file (JPG/PNG image file $\le$ 10MB)
  • Response Payload (200 OK):
{
  "label": "AI-Generated",
  "confidence": 1.00,
  "reliability": "High (Metadata Confirmed)",
  "heatmap": "<base64_encoded_png_image>",
  "metadata": {
    "has_exif": false,
    "camera_make": "N/A",
    "camera_model": "N/A",
    "software": "Stable Diffusion",
    "created_at": "N/A",
    "ai_tool_detected": "Stable Diffusion Metadata Signature",
    "file_type": "PNG",
    "dimensions": "1024 x 1024"
  }
}

πŸ§ͺ Running Backend Tests

Run the following scripts inside the backend directory to verify your installation:

cd backend

# Verify model service fallback architecture
python test_model.py

# Verify Grad-CAM activation mapping
python test_gradcam.py

# Verify FastAPI endpoint responses
python test_predict.py

☁️ Production Deployment

1. Backend on Render (Web Service)

  1. Go to your Render Dashboard.
  2. Create a New + -> Web Service or choose Blueprint (which automatically parses the root render.yaml file).
  3. Connect your repository.
  4. Set Root Directory to backend.
  5. Set the following environment variables:
    • PYTHON_VERSION = 3.11.7
    • FORCE_MOCK_MODE = true (Forces lightweight execution to prevent OOM on Render Free Tier)
    • ALLOWED_ORIGINS = *

2. Frontend on Vercel

  1. Go to your Vercel Dashboard.
  2. Import the same repository (Frenzy-codes/Deepguard).
  3. Set Root Directory to frontend.
  4. Add the following environment variable:
    • VITE_API_URL = Your live Render backend URL (e.g., https://deepguard-backend-yuuc.onrender.com).
  5. Click Deploy.

πŸ“œ License & Disclaimers

This project is open-source and intended solely for academic, research, and educational purposes. It is not designed to be used as legal evidence, forensic testimony, or for commercial content moderation.


Built with ❀️ by Team DeepGuard for Explainable AI research

About

Explainable AI (XAI) for Image Authenticity Detection. Combines a deep learning classifier (ResNet50 + Grad-CAM) with an advanced EXIF & AIGC metadata scanner to detect AI-generated images.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages