Pytune is an MLOps project that take place in a Datascientest training. The goal is to put into production a music recommender model based on the Implicit python library trained on the last.fm 1k dataset
This project put into action multiple technologies:
- FastApi (pytune api)
- MySQL (pytune database)
- Docker and docker-compose (virtualization)
- AirFlow (automation and model training)
- GitHub actions (CI/CD, unit test, docker build)
Both reports documenting "data science" and "MLOps" aspect of the projetc are available int the documentation root directory.
- Rapport fil rouge - Datascientest - PyTune.pdf
- Rapport MLOps - Datascientest - PytTune.pdf
project
│
└───documentation
│ │ Rapport fil rouge - Datascientest - PyTune.pdf
│ │ Rapport MLOps - Datascientest - PytTune.pdf
The project is build with modularity in mind so your not obliged to run all component. Sub-applications orchestrate around a core application. In order to make things simple all docker-compose uses the same predefined network (pytune).
-
CORE APP
- docker: pytune_api + pytune_bdd
- purpose: recommendation api and data base
-
AIRFLOW
- docker: airflow
- purpose: automation and monitoring
-
WEB APP
- docker: pytune_webapp
- purpose: front user interface
Set up and run pytune API and DataBase. Two options are available:
- using docker-compose
- using python
You can either build your own docker images using provided Dockerfiles or pull prefab from dockerhub
- alumet/pytune_api:latest
- alumet/pytune_mysql:latest
- pytune_api
docker image build . -t alumet/pytune_api:latest
- pytune_bdd
Follow instruction in database_docker/README.md
project └───database_docker │ │ README.md# run core app (api + bdd) docker-compose up -d
project │ └───webapp │ │
- alumet/pytune_webapp:latest
Follow instruction in webapp/README.md
project └───webapp │ │ README.md# run webapp cd webapp docker-compose up -d
Follow instruction in airflow/README.md
project └───airflow │ │ README.md
Update
atp update
apt install python3-dev default-libmysqlclient-dev build-essential python3-pipInstall requirements:
pip install -r requirements.txtInstall uvicorn server with:
sudo apt install uvicornFollow instruction from database_docker/Readme.md
project
└───database_docker
│ │ README.md
Create .env file from template
cp .env_template .envFile all Environment Variables with:
- DATA_BASE: url to database (mysql)
- MODEL_FOLDER: model folders (default production)
- PRODUCTION_MODEL: production model (default als_model.mdl)
! Place yourself in folder containing api.py !
uvicorn api:app
For both methods python or docker, open in browser: http://127.0.0.1:8000
Or test using curl
curl -X GET -i http://127.0.0.1:8000/Open in browser: http://127.0.0.1:8000/docs
admin user
{
"id": 0,
"username": "admin",
"password": "admin"
}test fakes users
{
"jazz":{
"id": 960,
"username": "user_jazz",
"password": "jazz"
},
"classic":{
"id": 961,
"username": "user_classic",
"password": "classic"
},
"pop":{
"id": 962,
"username": "user_pop",
"password": "pop"
},
"rock":{
"id": 963,
"username": "user_rock",
"password": "rock"
},
"rap":{
"id": 964,
"username": "user_rap",
"password": "rap"
}
}This cam be long (up to 15 min) and require at least 6Go of RAM
Once the model trained it should have been saved in then model folder
project └───production │ │ model_asl.mdl
Download model at https://www.dropbox.com/s/z8p5knhkn88884a/model_als.mdl?dl=0
Place file model_als.mdl in production folder
Step 3.2 required
# from project folder
python3 train.pycurl -X GET \
-i http://127.0.0.1:8000/admin/model/train \
-u "admin:admin"See airflow/Readme.md to set up
project
└───airflow
│ │ README.md
Load new model in API. Restart API server or use reload end point
curl -X GET \
-i http://127.0.0.1:8000/admin/model/reload \
-u "admin:admin"Search track title containing "smells"
curl -X POST \
-i http://127.0.0.1:8000/search?search=smells \
-u "admin:admin"Personalised Recommendation (change with user)
curl -X POST \
-i http://127.0.0.1:8000/recommendation \
-u "admin:admin" \
-d '{"N_track": 10,"filter_already_liked": false}' \
-H 'Content-Type: application/json'Add new user
curl -X POST \
-i http://127.0.0.1:8000/admin/user \
-u "admin:admin" \
-d '{"user_name": "aa", "pass_word": "aa", "is_admin": false}' \
-H 'Content-Type: application/json'