This project is a web-based tool that detects whether an image is real or AI-generated using a fine-tuned CVT (Convolutional Vision Transformer) model. It combines a Python backend with a simple HTML/JS frontend.
- Frontend image gallery with click-to-analyze interaction
- Flask backend with a
/serverTestendpoint - Pretrained CVT-13 backbone with a custom classifier
- Automatically downloads and analyzes the image
- Returns classification (
RealorAI Generated) with confidence score
main/
│
├── models/
│ ├── model_epoch_XX.pth # trained model weights
│ ├── custom_dataset.py
│ ├── model.py
│ ├── aidetector.py
│ ├── inference.py
│ ├── train.py
│ └── evaluate.py
│
├── server.py # Flask API server
│
└── website/
├── index.html
├── content_script.js
└── styles.css # (optional)
Make sure Python 3.9+ is installed. Then run:
pip install -r requirements.txtIf you don't already have model weights:
python3 main/train.py main/models/DATASET/train --total_epochs 10 --save_path main/modelsThis will generate .pth files like model_epoch_9.pth in the models/ folder.
Run the Flask server:
python3 main/server.pyIt will run on:
http://127.0.0.1:5000
Navigate to the website/ folder and run a static file server:
cd website
python3 -m http.serverThen open your browser and go to:
http://localhost:8000
- Click on an image in the gallery.
- The image will be sent to the backend.
- The server returns whether it's Real or AI Generated, along with the confidence level.
- The result is logged in the console or displayed (if UI supports it).
- Make sure the model file is inside
main/models/and named something likemodel_epoch_24.pth - The image URLs in the frontend must be accessible via full URLs (not
"images/dog.jpg") - This tool is for educational purposes — AI detection is an evolving field.
Created by Anna Scribner, Michael Gilbert, Muskan Gupta, and Roger Tang during NSC Hack4Impact - we won 1st prize!