Tutorial for deployment website in AWS instance can be found here
This is tutorial for local development on local machine
sudo -s
apt update
apt install -y npm
apt install -y python3.6 python3-pip
apt install -y nginx
apt update && apt install -y libsm6 libxext6
apt install libxrender1
apt install -y redis-server
apt install git
git clone https://github.com/thanhhau097/ml_project_template.git
cd ml_project_template
alias python=python3
alias pip=pip3
cd api
pip install -r requirements.txt
npm install
cd ../web
npm install
You need to config your AWS account in local machine: (optional, it is useful when you want to save uploaded data to AWS s3)
apt install awscli
aws configure
Change your bucket in AWS S3 (it is optional, when you need to upload user data to s3 bucket)
async_data = {
'data': {'image': image_utils.encode(image), 'result': result},
'bucket': 'your-bucket',
'object_name': 'file-path-in-bucket/{}.pkl'.format(file_name)
}
Comment out the SSL config in this file because you don't need domain name for local development (line 4-6, 29.41). If you want to deploy into production, please see this link.
There are 3 tasks that you need to do for your project:
- Write prediction for you model in
model/predictor.py
and update your weights in model/weights folder - Write your API in
api/app.py
using Flask framework (you can use the template that was written for image) - Write your web app using ReactJS (you can use the demo template that I wrote in
web/
)
Open multiple terminal windows, each process should be handle in one window.
- Web
cd web/
npm run build
npm run start
- Flask
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export PYTHONPATH=$PYTHONPATH:./
python api/app.py
- Redis
Change redis conf in /etc/redis/redis.conf
bind 0.0.0.0
systemctl stop redis
systemctl start redis
- Celery
Change 'redis://redis:6379/0' to 'redis://localhost:6379/0' because you are running redis in local machine
celery worker -A api.app.celery_app --loglevel=info
- Nginx
Change the app and web in nginx/nginx.conf file to 0.0.0.0
sudo -s
rm /etc/nginx/sites-enabled/default
cp nginx/nginx.conf /etc/nginx/sites-enabled/
systemctl reload nginx
Now you can go to your browser and see what is happening: 0.0.0.0
- Flask
- Redis
- ReactJS
- Nginx
- Certbot (optional, when you have a domain name)
- Celery
- Docker
- Jenkins (optional)