This project implements a full end-to-end MLOps workflow using FastAPI, DVC, Makefile automation, unit tests, API tests, linting, security scans, model quality checks, and an excellence-track webhook with ngrok.
The goal of the project is to build a reproducible ML pipeline for predicting medical insurance costs based on demographic and health factors.
mlops-optim/
│
├── src/
│ ├── app.py # FastAPI app (predict / health / model-info)
│ ├── model_pipeline.py # Prepare → Train → Evaluate pipeline logic
│ ├── prepare_stage.py # DVC stage: data cleaning + encoding
│ ├── train.py # DVC stage: model training
│ ├── check_quality.py # Quality gate: ensure metrics are acceptable
│ ├── webhook.py # Excellence: remote CI trigger endpoint
│
├── tests/
│ ├── test_api.py # API tests (health, model-info, predict)
│ ├── test_model_pipeline.py
│
├── data/ # Raw and intermediate data
├── models/ # Stored trained models
├── results/ # Metrics, evaluation results
│
├── dvc.yaml # Three-step DVC pipeline
├── dvc.lock
├── Makefile # Full CI workflow
├── requirements.txt
└── README.md
This layout follows best practices for modular, maintainable MLOps projects.
make setupThis creates .make-env/ (Python virtual environment) and installs all dependencies.
source .make-env/bin/activateTo reproduce all ML steps:
make dvc-reproStages run automatically:
- prepare → clean + encode dataset
- train → GradientBoostingRegressor
- evaluate → MAE, MSE, R² output to
results/metrics.json
Outputs are tracked via DVC.
Start the API:
make run-apiOr manually:
.make-env/bin/uvicorn src.app:app --reload| Endpoint | Description |
|---|---|
GET /health |
Service liveness check |
GET /model-info |
Returns metadata about the loaded model |
POST /predict |
Returns model prediction for encoded features |
http://127.0.0.1:8000/docs
The model expects numerically encoded features:
| Feature | Encoding |
|---|---|
| sex | female=0, male=1 |
| smoker | no=0, yes=1 |
| region | northeast=0, northwest=1, southeast=2, southwest=3 |
Example input:
{
"features": [19, 0, 27.9, 0, 1, 3]
}Example prediction response:
{
"prediction": 16884.92
}make testmake api-testAll tests must pass before CI succeeds.
Included in CI:
- pylint (score must remain 10/10)
- flake8
- ruff (optional)
- bandit (security scanner)
Run all checks together:
make ciThe Makefile orchestrates the full workflow:
make ci
This runs:
- pylint
- flake8
- bandit
- unit tests
- API tests
- DVC pipeline
If any step fails, CI stops.
This project includes an advanced MLOps feature:
POST /triggerTriggers:
make ci
.make-env/bin/uvicorn src.webhook:app --reload --port 9000curl -X POST http://127.0.0.1:9000/triggerExpose the webhook over HTTPS:
ngrok http 9000You will get a public URL like:
https://cafe-1234.ngrok-free.app/trigger
Trigger CI remotely:
curl -X POST https://cafe-1234.ngrok-free.app/triggerThis demonstrates advanced CI orchestration and earns full excellence marks.
The check_quality.py script:
- loads
results/metrics.json - verifies required performance thresholds
- stops CI if performance is unacceptable
This prevents merging a degraded model.
You now have:
- A fully operational ML training pipeline
- A production-like serving API
- A complete CI/CD workflow
- Reproducibility ensured via DVC
- Automated security checks
- A remote CI trigger mechanism
- A fully structured, documented, excellence-level MLOps project
Author : Hind Ch