The aim of this project is to create a usable piece of service that harnesses the inference capabilities of a deep learning model for stakeholders to consume. This web service can be queried to obtain the prediction of a dish from a trained neural network using the Amazon EC2 Instance
The client-side UI has been developed using React (JavaScript Library). The server-side code has been built using Flask (Python Framework). This application has been deployed on Amazon’s EC2 Instance and the NGINX server on the instance has been configured to allow HTTP requests to access the service provided by the Flask application. The underlying deep learning model that is used to predict the label of the item has been trained and developed using the TensorFlow Library.
-
Training a neural network on a local system or cloud servers like Google Colab.
-
Wrapping the model along with its inference logic into a flask application.
-
Developing a frontend using React and connecting it to the backend flask application.
-
Creating an EC2 instance and configuring the NGINX reverse proxy server to handle connections from users over the Internet.
-
Hosting the application on an AWS EC2 instance.
Training Code with Results and Detailed Analysis: link
Trained Models: link
-
Client-Side Setup.
-
Server-Side Setup.
-
Uploaded Project to GitHub so it can be cloned on to the instance.
-
Deployed Application to the Cloud (AWS EC2 Instance).
-
Install Nodejs (Setup instructions)
-
Install NPM (Setup instructions)
-
Install dependencies.
cd client
npm install --from-lock-json
npm audit fix
-
Copy
.env.example
as.env
. -
Change API url in
.env
.
- Get inside
client
folder.
cd client
-
Update
.env.example
as.env
and updateREACT_APP_API_URL
to API URL if needed. -
Run the client
npm run start
As a result, we can run the client-side of the application. The server-side application of the application needs to be running for the application to generate predictions.
- Builds the app for production to the
build
folder.
npm run build
The build instead of the entire client-side code needs to be uploaded to the server and this reduces the amount of space consumed. Using the above command, it correctly bundles React in production mode and optimizes the build for the best performance. The build is minified, and the filenames include the hashes.
-
Make sure you have the latest version of Python installed and pip.
-
Install All the Dependencies.
pip install requirements.txt
python server.py
-
Create EC2 instance using amazon console, also in security group add a rule to allow HTTP incoming traffic and connect to it.
-
Clone client build and server to the instance.
-
NGINX setup
- Install nginx on EC2 instance using these commands,
sudo apt-get update sudo apt-get install nginx
- Above will install nginx as well as run it. Check status of nginx using
sudo service nginx status
- Here are the commands to start/stop/restart nginx
sudo service nginx start sudo service nginx stop sudo service nginx restart
- Now you will see a message that displays, "welcome to nginx” which indicates that nginx server has been setup and is running successfully.
-
Now you need to copy all your code to EC2 instance. You can upload the application using git clone on the server.
-
After copying code on EC2 server now we can point nginx to load the website by default. For below steps,
- Create this file /etc/nginx/sites-available/ptd.conf. The file content looks like this,
server { listen 80; server_name ptd; root /home/ubuntu/Predict-that-Dish/client/build; index index.html; location /api/ { rewrite ^/api(.*) $1 break; proxy_pass http://127.0.0.1:5000; } }
- Create symlink for this file in /etc/nginx/sites-enabled by running this command,
sudo ln -v -s /etc/nginx/sites-available/ptd.conf
- Remove symlink for default file in /etc/nginx/sites-enabled directory,
sudo unlink default
- Restart nginx,
sudo service nginx restart
-
Now install python packages and start flask server
sudo apt-get install python3-pip
sudo pip3 install -r /home/ubuntu/Predict-that-Dish/server/requirements.txt
python3 /home/ubuntu/Predict-that-Dish/server/server.py
After successfully performing all the above steps, the Web Service can be accessed over the Internet using the EC2 Instance!
The model could be improved by increasing the number of layers and training the model over many more epochs. To improve performance even further we could potentially isolate the background noise by using an object detection network to create bounding boxes to focus on the relevant part of the image. A drawback to consider is the limited type of labels and would need to increase range for wide scale adoption in current stage. Will improve upon current results in the near future.