This project is an end-to-end Machine Learning solution designed to classify messages as either Spam (unwanted) or Ham (legitimate). Built with a production-ready MLOps mindset, it features a complete pipeline from data ingestion to deployment, using MongoDB for data storage and FastAPI for serving predictions.
For a comprehensive architectural breakdown, data pipeline analysis, and technical implementation details, developers are encouraged to read the Full Project Report.
- End-to-End Pipeline: Modular components for Data Ingestion, Validation, Transformation, Model Training, and Evaluation.
- Neuro-MF Integration: Utilizes a custom Model Factory (
neuro_mf) configuration for automated model selection and hyperparameter tuning. - MongoDB Storage: Simulates a real-world enterprise environment where training data is fetched from a NoSQL database.
- Experiment Tracking: Detailed logging and artifact management for every run.
- FastAPI Deployment: A high-performance web API provides a user-friendly interface for real-time predictions.
- Imbalance Handling: Built-in strategies (SMOTE) to handle class imbalance in SMS data.
- 🐳 Dockerized: Fully containerized for consistent deployment across any environment.
├── src/
│ ├── components/ # Core ML logic (Ingestion, Transformation, Trainer)
│ ├── pipeline/ # Orchestration scripts (Training & Prediction)
│ ├── entity/ # Data classes for config and artifacts
│ ├── constant/ # Hardcoded constants and paths
│ └── logger.py # Custom logging setup
├── notebooks/ # EDA and experiment sandboxes
├── templates/ # HTML frontend for the web app
├── app.py # FastAPI entry point
├── Dockerfile # Docker build instructions
├── docker-compose.yml # Docker orchestration
├── upload_data_mongodb.py # Script to upload raw CSV to MongoDB
├── report.md # Technical breakdown & architectural report
└── requirements.txt # Python dependencies
- Docker & Docker Compose (Recommended) OR Python 3.8+
- MongoDB (Atlas or Local)
This is the fastest way to get the project running without worrying about dependencies.
-
Clone the repository:
git clone https://github.com/manmit-s/spam-detection.git cd spam-detection -
Set up Environment Variables: Create a
.envfile in the root directory:MONGO_DB_URL="your_mongodb_connection_string"
-
Launch the Application:
docker-compose up --build
Access the application at:
http://localhost:8080
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Start the FastAPI server:
python app.py
Before first-time training, upload the seed data to your MongoDB:
# If using Docker:
docker exec -it spam-detection-app python upload_data_mongodb.py
# If running locally:
python upload_data_mongodb.pyTrigger the training pipeline via URL:
- Visit
http://localhost:8080/trainto start the training process. - Monitor progress in the logs or terminal.
- Go to the home page (
http://localhost:8080). - Enter an SMS message and click Predict.
Since this project is dockerized, you can deploy it to any cloud provider (AWS, Azure, GCP) by:
- Building the image:
docker build -t spam-detection-app . - Pushing to a Container Registry (e.g., Docker Hub).
- Running it on services like Azure App Service, AWS App Runner, or ECS.
Developed by Manmit Samal