Detect fake news in seconds with a robust ML ensemble model—lightning-fast predictions, reliably hosted on Railway.
A production‑ready FastAPI microservice that predicts whether a news article is Fake or Real using an ensemble ML model (TF‑IDF + VotingClassifier). Fully Dockerised, CI‑ready, and live on Railway.
- Features
- Live Demo
- Tech Stack
- Project Structure
- Local Setup
- Docker Usage
- API Reference
- Testing
- Environment Variables
- License
- Author
- Contributing
- 🧠 Ensemble ML pipeline (TF‑IDF + VotingClassifier)
- ⚡ FastAPI backend with automatic Swagger UI (
/docs
) - 🐳 Docker‑first design — build once, run anywhere
- 🧵 CI/CD ready with GitHub Actions and automated Codecov reports
- 🛡️ Typed request/response models & custom exception handling
- 🌐 CORS enabled for easy front‑end integration
$ curl https://fake-news-detector-co.up.railway.app/
{"message":"Fake News Detector API is up and running."}
Open /docs
for an interactive Swagger UI.



Use the Swagger interface to test endpoints, send JSON payloads, and view real-time predictions
- FastAPI & Uvicorn
- scikit‑learn & joblib
- Python 3.11
- Docker & Railway
- Pytest + Codecov
.
├── app/
│ ├── main.py # FastAPI entry‑point
│ ├── predictor.py # Prediction logic
│ ├── logging_config.py # Centralised logger
│ ├── exceptions.py # Custom exceptions
│ ├── schemas.py # Pydantic models
│ └── utils/
│ └── loader.py # Load model & vectorizer
├── models/
│ ├── ensemble_voting_model.pkl
│ └── tfidf_vectorizer.pkl
├── tests/ # Unit & integration tests
├── Dockerfile
├── requirements.txt
├── .dockerignore
├── .github/ # CI workflow
└── README.md
# 1. Clone
git clone https://github.com/XavierRolex/fake-news-detector.git
cd fake-news-detector
# 2. (Optional) Create & activate virtual env
python -m venv venv && source venv/bin/activate
# 3. Install deps
pip install -r requirements.txt
# 4. Create a .env file (see below)
echo "MODEL_PATH=models/ensemble_voting_model.pkl" >> .env
echo "VECTORIZER_PATH=models/tfidf_vectorizer.pkl" >> .env
# 5. Run the API
uvicorn app.main:app --reload
Visit http://127.0.0.1:8000/docs
for Swagger UI.
# Build image
docker build -t fake-news-api .
# Run container
docker run -p 8000:8000 fake-news-api
Health check
Response
{ "message": "Fake News Detector API is up and running." }
Predict if text is Fake or Real
Request
{ "text": "NASA confirms water on the Moon's surface." }
Response
{ "label": "Fake", "probability": 0.1099 }
pytest --cov=app
Coverage reports are uploaded automatically to Codecov via GitHub Actions.
Key | Description | Default |
---|---|---|
MODEL_PATH |
Path to the trained model | models/ensemble_voting_model.pkl |
VECTORIZER_PATH |
Path to TF‑IDF vectorizer | models/tfidf_vectorizer.pkl |
LOG_LEVEL |
Logging level | INFO |
Note: On Railway, these are configured via the Variables tab.
Distributed under the MIT License. See LICENSE
for details.
Nafis Anzum
Contributions are welcome! Please open an issue first to discuss your ideas, or submit a pull request.
© 2025 Nafis Anzum – All rights reserved.