Skip to content

SanjayPhilip/modelforge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ ModelForge β€” End-to-End MLOps Pipeline

Python 3.11 FastAPI MLflow Docker GitHub Actions

A production-ready MLOps pipeline that demonstrates the complete lifecycle of a machine learning model β€” from training and experiment tracking to containerization and cloud deployment.

πŸ“‹ Table of Contents

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GitHub    │────▢│ GitHub      │────▢│   Docker    │────▢│   Render/   β”‚
β”‚   Repo      β”‚     β”‚ Actions     β”‚     β”‚   Hub       β”‚     β”‚   AWS       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                   β”‚                   β”‚                   β”‚
       β–Ό                   β–Ό                   β–Ό                   β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Code   β”‚        β”‚  Tests  β”‚        β”‚  Build  β”‚        β”‚  Deploy β”‚
  β”‚  Push   β”‚        β”‚  Train  β”‚        β”‚  Image  β”‚        β”‚  API    β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β–²
                                                          β”‚
                                                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                   β”‚   MLflow    β”‚
                                                   β”‚  (Tracking) β”‚
                                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

  • 🎯 ML Model Training β€” RandomForest regression on California Housing dataset
  • πŸ“Š Experiment Tracking β€” Full MLflow integration for parameters, metrics, and artifacts
  • 🐳 Containerization β€” Multi-stage Docker build for optimized production images
  • πŸ”„ CI/CD Pipeline β€” Automated training, testing, and deployment via GitHub Actions
  • 🌐 REST API β€” FastAPI with auto-generated docs, batch predictions, and health checks
  • πŸ“ˆ Monitoring Ready β€” Prometheus/Grafana hooks for production observability
  • ☁️ Cloud Deployed β€” One-click deployment to Render, AWS, or Railway

πŸ› οΈ Tech Stack

Layer Technology
API Framework FastAPI
ML Framework Scikit-learn, XGBoost
Experiment Tracking MLflow
Containerization Docker, Docker Compose
CI/CD GitHub Actions
Database PostgreSQL (MLflow backend)
Cloud Render / AWS EC2 / Railway
Testing Pytest

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Docker & Docker Compose
  • Git

1. Clone & Setup

git clone https://github.com/SanjayPhilip/modelforge.git
cd modelforge

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Environment Configuration

cp .env.example .env
# Edit .env with your credentials (optional for local development)

3. Train the Model

# Train with default parameters
python ml/train.py

# Or with custom hyperparameters
python ml/train.py --n-estimators 200 --max-depth 15

4. Run API Locally

# Option A: Direct Python
uvicorn api.main:app --reload

# Option B: Docker Compose (Full stack with MLflow)
cd docker
docker-compose up -d

# Access API: http://localhost:8000
# Access MLflow UI: http://localhost:5000
# Access API Docs: http://localhost:8000/docs

5. Make Predictions

# Health check
curl http://localhost:8000/api/v1/health

# Single prediction
curl -X POST "http://localhost:8000/api/v1/predict" \
  -H "Content-Type: application/json" \
  -d '{"features": [8.3252, 41.0, 6.9841, 1.0238, 322.0, 2.5555, 37.88, -122.23]}'

# Batch prediction
curl -X POST "http://localhost:8000/api/v1/predict/batch" \
  -H "Content-Type: application/json" \
  -d '{"features": [[8.3252, 41.0, 6.9841, 1.0238, 322.0, 2.5555, 37.88, -122.23], [8.3014, 21.0, 6.2381, 0.9718, 2401.0, 2.1098, 37.86, -122.22]]}'

πŸ“š API Documentation

Once running, interactive API documentation is available at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Endpoints

Method Endpoint Description
GET / API info and links
GET /health Health check with model status
GET /ready Kubernetes readiness probe
GET /live Kubernetes liveness probe
GET /api/v1/health Detailed health check
GET /api/v1/info Model metadata
POST /api/v1/predict Single prediction
POST /api/v1/predict/batch Batch predictions

πŸ”„ CI/CD Pipeline

Pull Request Flow

Push to PR branch
    β”‚
    β–Ό
GitHub Actions Triggered
    β”‚
    β”œβ”€β”€β–Ά Install Dependencies
    β”œβ”€β”€β–Ά Run Pytest (Unit + Integration)
    β”œβ”€β”€β–Ά Train Model
    └──▢ Upload Model Artifact

Main Branch Deployment

Push to main branch
    β”‚
    β–Ό
GitHub Actions Triggered
    β”‚
    β”œβ”€β”€β–Ά Build Docker Image
    β”œβ”€β”€β–Ά Push to Docker Hub
    └──▢ Deploy to Render (via webhook)

🌐 Deployment

Option A: Render (Recommended β€” Free Tier)

  1. Create a Web Service on Render
  2. Connect your Docker Hub image: sanjayphilip/modelforge:latest
  3. Set environment variables in Render dashboard
  4. Add RENDER_DEPLOY_HOOK to GitHub Secrets for auto-deployment

Option B: AWS EC2

# SSH into your EC2 instance
ssh -i your-key.pem ubuntu@your-ec2-ip

# Install Docker
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker ubuntu

# Pull and run
docker pull sanjayphilip/modelforge:latest
docker run -d -p 80:8000 --name modelforge sanjayphilip/modelforge:latest

Option C: Railway (Your Existing Stack)

  1. Connect GitHub repo to Railway
  2. Railway auto-detects Dockerfile
  3. Add PostgreSQL plugin for MLflow backend

πŸ“ Project Structure

modelforge/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       β”œβ”€β”€ train.yml          # PR: Train + Test + Evaluate
β”‚       └── deploy.yml         # Main: Build + Push + Deploy
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ main.py                # FastAPI app entry point
β”‚   β”œβ”€β”€ router.py              # API route handlers
β”‚   └── schemas.py             # Pydantic request/response models
β”œβ”€β”€ ml/
β”‚   β”œβ”€β”€ train.py               # Training script with MLflow
β”‚   β”œβ”€β”€ evaluate.py            # Model evaluation utilities
β”‚   β”œβ”€β”€ predict.py             # Inference wrapper
β”‚   └── utils.py               # Data preprocessing
β”œβ”€β”€ models/                    # Trained models (gitignored)
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                   # Raw datasets
β”‚   └── processed/             # Cleaned datasets
β”œβ”€β”€ notebooks/
β”‚   └── eda.ipynb              # Exploratory Data Analysis
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_api.py            # API endpoint tests
β”‚   └── test_ml.py             # ML pipeline tests
β”œβ”€β”€ docker/
β”‚   β”œβ”€β”€ Dockerfile             # Multi-stage build
β”‚   └── docker-compose.yml     # Full stack orchestration
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ setup.py
β”œβ”€β”€ .env.example
└── README.md

πŸ“Έ Screenshots

MLflow UI MLflow experiment tracking dashboard

πŸ—ΊοΈ Roadmap

  • Add Prometheus + Grafana monitoring
  • Implement model versioning and A/B testing
  • Add data drift detection
  • Integrate with AWS SageMaker
  • Add authentication to API endpoints
  • Build Streamlit frontend for interactive predictions
  • Add model explainability (SHAP values)

πŸ‘€ Author

Sanjay Philip

  • GitHub: @SanjayPhilip
  • MCA Final Year | Saintgits College of Engineering, Kerala, India
  • Passionate about Web Development, AI/ML, and Cybersecurity

πŸ“„ License

This project is licensed under the MIT License.


⭐ Star this repo if you find it useful!

About

End-to-End MLOps Pipeline: Train, track, containerize, and deploy ML models via FastAPI REST API with automated CI/CD on Render.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors