Skip to content

Repository files navigation

AI Video Detection

This project now supports three layers:

  • a FastAPI backend that accepts uploads and runs video analysis
  • a Streamlit frontend for interactive testing
  • an ML pipeline for preparing datasets and training a reusable frame classifier

Dataset layout

Put your raw videos into class-labeled folders:

data/
  raw/
    ai_generated/
      sample_01.mp4
      sample_02.mov
    real/
      clip_01.mp4
      clip_02.avi

The dataset prep script will extract evenly spaced frames from each video and create leakage-safe train, val, and optional test splits by video.

Recommended dataset: DeepAction

DeepAction is a strong starting point because it already pairs real human-action videos with multiple text-to-video model outputs. A dedicated importer is included:

python import_deepaction.py --max-videos 200

This script imports:

  • Pexels videos into data/raw/real
  • BDAnimateDiffLightning, CogVideoX5B, RunwayML, StableDiffusion, Veo, and VideoPoet into data/raw/ai_generated

If the datasets package is missing, install a compatible version first:

python -m pip install "datasets==3.0.6"

Prepare the dataset

python -m ml_models.prepare_dataset --raw-data-dir data/raw --output-dir data/processed/frames --frames-per-video 16 --overwrite

That creates a structure like:

data/
  processed/
    frames/
      train/
      val/
      test/
      dataset_manifest.json

Train the model

python -m ml_models.train_model --data-dir data/processed/frames --output-dir ml_models/weights --epochs 10 --batch-size 8

Training writes:

  • ml_models/weights/best_model.pth
  • ml_models/weights/training_metrics.json

The detector automatically reads ml_models/weights/best_model.pth if it exists.

Run the app

Start the API:

uvicorn backend.main:app --reload

Then start the frontend in another terminal:

streamlit run frontend/app.py

Notes

  • Without trained weights, the app falls back to heuristic analysis so the product still works.
  • Better results depend heavily on dataset quality, label accuracy, and diversity across generators, codecs, and resolutions.
  • The current classifier is frame-based. A stronger next step would be adding temporal features or a video transformer.

About

A deep learning tool that detects whether a video is AI-generated or real using EfficientNet-B4, FastAPI, and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages