Deepfake Document Detection API — AI-powered detection of manipulated document images using U-Net segmentation.
CertiScan Backend is a FastAPI-based REST API for detecting document forgery and deepfake manipulation. Upload an image and receive a confidence score and visual mask showing potentially manipulated regions.
- Model: U-Net with EfficientNet-B0 encoder
- Framework: FastAPI + Uvicorn
- Deployment: Ready for Vercel serverless
# Clone and navigate to project
cd backend
# Create and activate virtual environment
python -m venv .venv
. .venv/Scripts/Activate.ps1 # Windows PowerShell
source .venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txt
# Run server
uvicorn main:app --reloadServer will be at http://127.0.0.1:8000
View interactive API docs: http://127.0.0.1:8000/docs
Deploy this backend as serverless functions to Vercel:
- Push to GitHub
- Connect repo to Vercel
- Set environment variables (see
.env.example):UNET_MODEL_PATH— path to model checkpointCORS_ORIGINS— comma-separated frontend domains
- Deploy — Vercel auto-detects
vercel.jsonconfig
VERCEL_DEPLOYMENT.md — Complete setup guide with troubleshooting
- ⏱️ Vercel functions have a 60-second timeout (model loading takes 15-30s)
- 💾 No persistent storage — output masks are returned as encoded data
- 🌡️ Cold starts cause slowdowns — pre-warm with periodic health checks
See VERCEL_DEPLOYMENT.md for workarounds and best practices.
curl http://localhost:8000/healthcurl -F "file=@document.jpg" http://localhost:8000/predictResponse:
{
"prediction": "Real",
"confidence": 0.95,
"threshold_used": 0.1,
"model_version": "unet_finetuned_v2.pth",
"mask_path": "outputs/abc123.png",
"mask_url": "http://localhost:8000/outputs/abc123.png"
}See .env.example for all available options:
UNET_MODEL_PATH— path to model checkpointCORS_ORIGINS— comma-separated list of allowed CORS originsALLOW_UNTRAINED_MODEL— allow running without trained weights (dev only)
.
├── backend/
│ ├── main.py # FastAPI app
│ ├── routes/predict.py # Prediction endpoint
│ ├── model/loader.py # Model loading
│ ├── utils/
│ │ ├── preprocess.py # Image preprocessing
│ │ └── inference.py # Model inference
│ ├── unet_finetuned_v2.pth # Model weights
│ └── README.md # Detailed backend docs
├── Procfile # Railway config
├── runtime.txt # Python version
├── Dockerfile # Container config
├── requirements.txt # Python dependencies
└── .env.example # Environment template
pip install pytest
pytest -qSee backend/README.md for detailed troubleshooting guide.
Common issues:
- Model not found: Set
UNET_MODEL_PATHor useALLOW_UNTRAINED_MODEL=1(dev) - CORS errors: Update
CORS_ORIGINSenvironment variable - Port in use: Change port in development or check for existing process
- Create feature branches from
main - Keep commits focused and well-documented
- Add unit tests for new features
- Update
requirements.txtwhen adding dependencies
[Add license info here]
For detailed backend documentation, see backend/README.md