Skip to content

A web application that detects if an image is real or AI-generated using statistical gradient analysis. Features a modern Svelte frontend and FastAPI backend for instant image authenticity detection.

Notifications You must be signed in to change notification settings

aaliyanahmed1/AI_Image_detector

Repository files navigation

Image Authenticity Detector

A simple web application that detects if an image is real or AI-generated. No training required - works immediately! Features a modern Svelte frontend and FastAPI backend.

How It Works

The baseline detector uses statistical feature analysis:

  1. Extract Features: Gradient variance, entropy, edge density, luminance statistics
  2. Rule-Based Classification: Real images have higher variance/entropy, AI images are smoother
  3. Output: Label (real/ai) with confidence score

No training required - works immediately on any image!

Installation

Quick Install (Windows)

INSTALL.bat

Manual Installation

1. Install Python dependencies:

python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

2. Install frontend dependencies:

cd frontend-svelte
npm install
cd ..

Running the Application

Quick Start (Windows)

RUN_ALL.bat

Manual Start

Terminal 1 - Backend:

venv\Scripts\activate
python app.py

Terminal 2 - Frontend:

cd frontend-svelte
npm run dev

Access:

Usage

  1. Detect: Upload an image → Get instant result (real or AI)
  2. Analytics: View detection statistics and history

No training needed - the baseline detector works immediately!

Python API Usage

from baseline_detector import predict

# Predict on an image (no training needed!)
result = predict("path/to/image.jpg")
print(f"Label: {result['label']}")
print(f"Confidence: {result['confidence']:.2%}")
print(f"Reasons: {result['reasons']}")

Output Format

{
    "label": "real" or "ai",
    "confidence": 0.0-1.0,
    "score": float,
    "features": {...},
    "reasons": ["reason1", "reason2", "reason3"]
}

Features

  • No Training Required: Works immediately on any image
  • Fast Detection: <0.5 seconds per image
  • Statistical Analysis: Uses gradient patterns to detect AI images
  • Simple API: Just upload and get results
  • Web Interface: Modern Svelte frontend

Requirements

Backend:

  • Python 3.8+
  • FastAPI, Uvicorn
  • NumPy, SciPy, scikit-learn
  • OpenCV

Frontend:

  • Node.js 18+
  • npm/yarn/pnpm

See requirements.txt for complete Python dependencies.

Performance

  • Accuracy: ~70-75% (baseline)
  • Speed: <0.5 seconds per image
  • No Training: Works immediately
  • Lightweight: Minimal dependencies

For better accuracy, consider implementing neural network approaches (EfficientNet, Vision Transformer).

License

This implementation follows the mathematical pipeline described in the reference image and is provided as-is for research and educational purposes.

About

A web application that detects if an image is real or AI-generated using statistical gradient analysis. Features a modern Svelte frontend and FastAPI backend for instant image authenticity detection.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published