A microservice built on Flask to deploy ML models as rest api.
This code can be used as a boilerplate for your next machine learning project deployment. Replace project/sentiment/ml_models/model.py with your custom model architecture file.
- Create virtual or conda environment and activate it
Windows
virtualenv restenv
restenv\Scripts\activate
Linux
python3 -m venv restenv
source restenv/bin/activate
- Install dependencies
Edit line 15-17 in requirements.txt according to your OS
pip install -r requirements.txt
- Install spacy model
python -m spacy download en_core_web_sm
- To start the microservice in dev environment
python manage.py start --env=dev
- To start the microservice in production environment
python manage.py start
- To access swagger api, open http://localhost:5000/api/v1/
- To run tests
python manage.py test
- Code coverage
python manage.py cov
URL: http://localhost:5000/api/v1/sentiment
{
"text": "i am so happy"
}
{
"status": "success",
"message": {
"text": "i am so happy",
"sentiment": "positive",
"confidence": 0.9986
}
}
URL: http://localhost:5000/api/v1/sentiments
{
"texts": [
{
"text": "i am so happy"
},
{
"text": "I am so SAD"
},
{
"text": "today is a Good day"
}
]
}
{
"status": "success",
"message": [
{
"status": "success",
"text": "i am so happy",
"sentiment": "positive",
"confidence": 0.9986
},
{
"status": "success",
"text": "I am so SAD",
"sentiment": "negative",
"confidence": 0.9993
},
{
"status": "success",
"text": "today is a Good day",
"sentiment": "positive",
"confidence": 0.9989
}
]
}
URL: http://localhost:5000/api/v1/
TODOs ⏰
- add sentiment analysis model
- update api
- add tests
- add logging
- add load testing
- add database to store predictions
- dockerize the app
- add authentication