GithubHelp home page GithubHelp logo

yueyang0115 / covid-prediction-ml-flask-app-on-gae Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 53 KB

This project built a ML model and deployed it on Flask. The Flask app is deployed to Google App Engine.

Makefile 5.78% Python 39.54% Shell 12.55% HTML 42.12%
sklearn flask google-app-engine cloud-build machine-learning google-cloud-platform locust continuous-deployment

covid-prediction-ml-flask-app-on-gae's Introduction

Covid Prediction Flask App on GAE

Author: Yue Yang, Jingyi Xie, Jiateng Mao

Overview

In this project, we built a machine learning model to predict the number of Covid positive cases and deployed it on Flask. The Flask app is deployed to Google App Engine(GAE) and can be accessed through a public url. We configured Cloud Build for continuous deployment(CD). We also verified the elastic scale-up performance via load test with Locust.

The workflow of this project is as below:
architecture2

Here is an image of the frontend website:
CleanShot 2021-04-20 at 22 06 08 Here is an image of the load test result. It shows that our app can scale to 1K+ requests served by multiple endpoints.
CleanShot 2021-04-20 at 21 42 03

Reference

Souece Code: github.com/noahgift/container-revolution-devops-microservices
Souece Code: github.com/johnnyAklilu/USCOVID19CasePredictorUpdated
Souece Code: github.com/chugh007/FlightPricePrediction
Souece Code: github.com/yueyang0115/flask-app-GCP-deploy

How to build from scratch

Read through the files and understand how it works.

  • main.py is the main workflow of the project. It trains model and directs to the flask web.
  • national-history-update.csv is the dataset for training the ML model.
  • Makefile is used for installing packages and others.
  • requirements.txt is required for the Makefile.
  • app.yaml is required for deployment on Google App Engine.
  • cloudbuild.yaml is required for continuous deployment with Cloud Build.
  • locustfile.py is required for load test via locust.
  • predict-local.sh is required for testing the app which runs locally by sending POST request to it through script.
  • predict.sh is required for testing the app which runs on cloud by sending POST request to it through script.
  • /templates folder contains the templete html page for the flask app.

To build this project from scratch, you can follow these steps:

Set up project

Launch Google Cloud Platform, create a new project. Change your current project to it and activate Cloud Shell.
To configure CD with Cloud Build, you will need to create your own github repo. Otherwise you can just git clone this repo and skip the steps below.
Create ssh-keys and upload it to Github.

ssh-keygen -t rsa

Create a new repo on github, git clone it to your GCP local and cd into it. Upload all the files in this repo to your new repo.

Run this app locally

Create a virtual environment and activate it. (To deactivate it, run deactivate).

make set-up
source ~/.covid_venv/bin/activate

Install the required packages.

make install

Run this app, the flask app will be running on http://127.0.0.1:8080/.

python3 main.py

You can test it from the frontend website or send a POST request to the running app through a script.

bash predict-local.sh

Deploy this app to GAE

(optional) Verfiy the current project is working. Switch your project if it's not what you want.

gcloud projects describe $GOOGLE_CLOUD_PROJECT
gcloud config set project $GOOGLE_CLOUD_PROJECT

Create app engine in GCP.

gcloud app create 

When it asks you to choose a region, select one(in my case is 14 us-central). Type "yes" when it asks you to continue.
Deploy this app on cloud, the app will be running on the provided public url.

gcloud app deploy

You can test it from the frontend website or send a POST request to the running app through a script. Remember to change the website address in predict.sh.

bash predict.sh

Set up CD with Cloud Build

Documents: Automate App Engine deployments with Cloud Build.
Create cloudbuild.yaml file. Open GCP Cloud Build console.
Select Trigger and create a new trigger, set repository event to "Push to a branch", connnect your related github repository as the source to watch for events, chosse master branch.
Select "settings", then click on "Cloud Build service account". In the newly open documenation, click on "Open the Cloud Build Settings page". In the new page, enable App Engine and Service accounts.
gcp

Now, if you make a new push, this app will be redeployed automatically and you can find the pipeline under Cloud Build.

Load test with locust

Run following command, the locust server will be running on http://0.0.0.0:8089/.

locust

Go to the webpage, fill out the form and try to test it.
locust

Done!

covid-prediction-ml-flask-app-on-gae's People

Contributors

jingyi-xie avatar yueyang0115 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.