Skip to content

coder-msk/DeepDeception---AI-Powered-Deepfake-Detection

Repository files navigation

DeepDeception

A deep-learning web application for deepfake video detection, built with Django, TensorFlow/Keras (Xception), and OpenCV. The system was developed as a Final Year Project at Bahria University.

Users upload an MP4 clip; the backend checks for visible faces, extracts face crops from sampled frames, runs each crop through a fine-tuned Xception classifier, and shows an aggregate verdict with per-frame confidence and charts on the results page.


Screenshots

Landing / upload experience

DeepDeception landing and upload UI

Detection results (charts and verdict)

DeepDeception results with confidence and charts

What this repository contains

Area Description
Web app Django project deepfake_detector, app app, templates under templates/
Inference app/views.py — face detection (Haar cascade), frame capture, duplicate filtering (ImageHash), Xception preprocessing and prediction
Model weights Downloaded at runtime from Hugging Face Hub (not stored in git) — see Model
Database SQLite by default (db.sqlite3); models for newsletter emails and feedback
Deployment Dockerfile + Gunicorn; WhiteNoise for static files; suitable for Railway or similar platforms

Standalone training notebooks/scripts are not included in this repo; the shipped code focuses on inference and the web UI. Training was done separately; the resulting .h5 weights are published on Hugging Face for use by this app.


Core features

  • Xception-based detection — Face crops resized to 224×224, Xception preprocess_input, binary output interpreted so higher score → fake (see evaluate_frames in app/views.py).
  • Face-aware pipeline — Rejects videos with no detectable faces (quick scan across sampled frames).
  • Frame extraction — Periodic sampling (frame_skip = 20), minimum face size and brightness filters, perceptual hashing to drop near-duplicates.
  • Results UI — Overall label, average confidence, real/fake counts, ApexCharts series for exploration; optional export helpers (PDF/Excel libraries loaded in templates/results.html).
  • Newsletter — Email collection via Email model and email_submission API.
  • Feedback — Star rating + comment + page URL + IP, stored via Feedback and submit_feedback.
  • Cancel processingPOST/GET to cancel_processing/ sets a global flag so long jobs can be aborted between stages.
  • Resource-conscious inference — TensorFlow configured for CPU, limited threading, and memory cleanup helpers to behave better on constrained hosts.

Tech stack

Layer Technology
Framework Django 3.2
Deep learning TensorFlow 2.10, Keras, Xception
Vision OpenCV (Haar frontal-face cascade), Pillow, ImageHash
Model delivery huggingface_hub (hf_hub_download)
Server Gunicorn, WhiteNoise
Frontend HTML, Tailwind (CDN on results page), ApexCharts, Font Awesome

How detection works (code path)

  1. upload_video (app/views.py) accepts MP4 only (VideoUploadForm / clean_video in app/forms.py).
  2. Upload is saved under MEDIA_ROOT; previous media/ tree is cleared for a clean run.
  3. check_faces_in_video scans up to ~10 spread-out frames; if no face → JSON error No faces detected.
  4. FrameCapture reads the video, every 20th frame runs Haar detection, saves face crops under media/frames/, then remove_non_face_and_duplicate_frames deduplicates.
  5. evaluate_frames loads each image with Keras image.load_img(..., target_size=(224, 224)), applies Xception preprocessing, model.predict, aggregates mean of the fake probability across frames, and decides Real vs Fake (threshold 0.5 on that mean).
  6. Results are rendered in templates/results.html with chart series passed as JSON.

Model loading (once at import):

def load_model_from_hf():
    model_path = hf_hub_download(
        repo_id="abdulrehman77/deepfakedetection",
        filename="XSoftmax- 1st high P.h5",
        cache_dir=os.path.join(settings.BASE_DIR, 'models')
    )
    return tf.keras.models.load_model(model_path, compile=False)

model = load_model_from_hf()

Model and training

  • Architecture: Xception (ImageNet-style input, fine-tuned for binary real/fake).
  • Training data: Described in project documentation as aligned with the Deepfake Detection Challenge (DFDC) style real vs. fake video data.
  • Weights: Hosted on Hugging Face: repo abdulrehman77/deepfakedetection, file XSoftmax- 1st high P.h5. The app downloads this file on first run into models/ (cache).
  • Validation performance (reported): on the order of ~94% accuracy on the held-out validation setup used for the FYP (exact split and metric definitions follow the training notebook — not bundled here).

Training code: Training notebooks or scripts are not part of this repository. To retrain, you would typically:

  1. Prepare face crops or frames from real and fake sources (e.g. DFDC or similar).
  2. Fine-tune Xception with binary cross-entropy (or equivalent), match input size 224×224 and Xception preprocessing.
  3. Export .h5 and either place it locally or upload to Hugging Face and point hf_hub_download at your file.

Project layout

deepfakeDetection-main/
├── app/
│   ├── views.py          # Inference pipeline, APIs (feedback, email, cancel)
│   ├── forms.py          # VideoUploadForm (MP4), email form
│   ├── models.py         # Email, Feedback
│   ├── urls.py           # Routes for upload, cancel, feedback, newsletter
│   └── admin.py          # Admin for Email & Feedback
├── deepfake_detector/
│   ├── settings.py       # DB, static/media, WhiteNoise, upload limits
│   ├── urls.py           # Root URLconf (admin + app)
│   └── wsgi.py           # Gunicorn entry
├── templates/
│   ├── landing_page.html # Main upload UI
│   ├── results.html      # Results + charts
│   ├── base.html, login.html, signup.html
├── media/                # Created at runtime (uploads, frames) — not for git
├── models/               # HF cache for downloaded .h5 — created at runtime
├── requirements.txt
├── Dockerfile
├── install.sh            # pip helper (numpy first)
├── manage.py
└── README.md

Requirements

  • Python 3.9–3.10 recommended (matches TensorFlow 2.10.1 wheels on common platforms).
  • FFmpeg is not invoked directly in code; OpenCV reads videos — ensure codecs your OS supports for MP4.
  • Internet on first run to download weights from Hugging Face.

How to run locally

1. Clone and enter the project

git clone https://github.com/coder-msk/DeepDeception---AI-Powered-Deepfake-Detection.git
cd DeepDeception---AI-Powered-Deepfake-Detection

2. Virtual environment (recommended)

python -m venv venv
source venv/bin/activate          # Windows: venv\Scripts\activate

3. Install dependencies

Either:

chmod +x install.sh
./install.sh

or:

pip install --no-cache-dir numpy==1.26.4
pip install -r requirements.txt

4. Database

python manage.py migrate

Optional admin user:

python manage.py createsuperuser

5. Run the dev server

python manage.py runserver

Open http://127.0.0.1:8000/ — upload an MP4 that contains clear faces.


Production-style run (Gunicorn)

After collectstatic (WhiteNoise serves from STATIC_ROOT):

python manage.py collectstatic --noinput
gunicorn deepfake_detector.wsgi:application --bind 0.0.0.0:8000

For platforms that inject PORT (e.g. Railway), bind to 0.0.0.0:$PORT in your process manager or container entrypoint.


Docker

Build and run (adjust port as needed):

docker build -t deepdeception .
docker run -p 8080:8080 -e PORT=8080 deepdeception

Note: The Dockerfile uses Gunicorn; ensure PORT matches your platform’s expectations. If $PORT is not expanded inside the container CMD, set the bind address in a way your host documents (shell form or explicit port).


API routes (summary)

Method / path Purpose
GET / Upload page (upload_video)
POST / Submit MP4 for analysis
POST/GET /cancel_processing/ Cancel ongoing processing
POST /api/feedback/ JSON feedback (rating, comment, page_url)
POST /newsletter/submit-email/ JSON { "email": "..." }
/admin/ Django admin (emails & feedback)

Configuration notes

  • DEBUG, SECRET_KEY, and ALLOWED_HOSTS in deepfake_detector/settings.py are suitable for development only. For production, use environment variables, a strong secret, DEBUG=False, and restricted hosts.
  • Upload limit: about 100 MB per DATA_UPLOAD_MAX_MEMORY_SIZE / FILE_UPLOAD_MAX_MEMORY_SIZE.
  • TensorFlow is forced to CPU in app/views.py for predictable behavior on shared servers.

Authors

  • Muhammad Salman Khan
  • AbdurRehman
  • Maheen Sheikh

Acknowledgments

Final Year Project, Bahria University. Deepfake research and datasets such as DFDC informed the modeling choices; the Xception architecture is due to its authors via Keras Applications.

About

DeepDeception is a deepfake detection web app using Django and TensorFlow (Xception) to analyze video frames, detect faces, and classify real vs. fake content with confidence scores and visual charts. Features frame extraction, image deduplication, and scalable deployment via Docker.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages