This serves as a reference and a demo on how to serve models with LightGBM, Flask, gunicorn, nginx, and redis
The task is to create a Web Service that serves a model that predicts the Income Bracket using Adult Census Dataset
Model Training is implemented at training
folder.
- Web Service that uses
Flask
,gunicorn
, andnginx
✔️ - Uses
redis
for caching ✔️ POST
driven endpoint ✔️- Model Feature Engineering ✔️
- Hyperparameter Tuning (LGBM w/ Bayesian Optimization) ✔️
- docker + docker-compose ✔️
- Unit Testing + Github Actions ✔️
Two options are available, either with docker-compose
or terraform
The simplest way to run the Web Server is to use docker-compose
. In this exact location of this repository simply type:
docker-compose up -d --build
Where it spins-up three Docker Containers. Namely:
- Container for
Flask
andgunicorn
- Container for
nginx
- Container for
redis
You can use the following endpoint locally
http://0.0.0.0:1337/predict_income
Where it takes a sample payload from a POST
request
You can also run this with terraform
. Simply run the following
terraform init
terraform plan
terraform apply
If you want to destroy the docker containers simply
terraform destroy
For more details, go to sample_payload
directory. You'll find a sample file, and a sample script to execute.
{'age': 82,
'workclass': 'Private',
'fnlwgt': 132870,
'education': 'HS-grad',
'marital.status': 'Widowed',
'occupation': 'Exec-managerial',
'relationship': 'Not-in-family',
'race': 'White',
'sex': 'Female',
'capital.gain': 0,
'capital.loss': 4356,
'hours.per.week': 18,
'native.country': 'United-States'}
And receives an output
{'predicted_income_class': '<=50k', 'prediction_raw': 0.08823289115946195, 'status': 'success'}
Unit Test is triggered on push and pull-request events