In this project, we used regression model and imported dataset from kaggle to train it. We used Flask to build a light-weight web framework to predict the future population in China. And then we deploy our service in GCP and used locust to load test it.
The introduction video of our project: https://youtu.be/zTXA0Jn-ezI
- Clone the repo
git@github.com:xzhnshng/IDS721-group-project.git
- Create & enter python virtual environment
# first cd to the project directory
# create virtual environment
python -m venv env
# enter the virtual environment
source env/bin/activate
- Setup - Install the required packages
make all
- Train the model
python model.py
- Run the application
python main.py
The dataset is from https://www.kaggle.com/datasets/anandhuh/population-data-china
# create image
docker build -t population-predictor:latest .
# create and run container
docker run --rm -p 5000:5000 --name population-predictor-app population-predictor:latest
Now you can access service on http://127.0.0.1:5000/
-
Create a new project and check if the project correct and set working project if not. In this step you need to record the , which will be used in next steps:
gcloud projects describe $GOOGLE_CLOUD_PROJECT
gcloud config set project $GOOGLE_CLOUD_PROJECT
-
Paste command below on the GCP shell:
git clone git@github.com:xzhnshng/IDS721-group-project.git
-
In the project folder, build the containerized flask application image:
gcloud builds submit --tag gcr.io/<PROJECT-ID>/app
-
Last step, deploy the image on the cloud run service:
gcloud run deploy --image gcr.io/<PROJECT-ID>/app --platform managed
And you will need to name your service and select region you want to deploy.
Lastly, you can see the service running on the given URL:
I used https://locust.io/ to start load testing for the flask project.
-
Download locust
pip3 install locust
-
Write locustfile.py:
import time from locust import HttpUser, task, between class QuickstartUser(HttpUser): @task def submitForm(self): self.client.post("/predict", {"Year":"2024"})
-
Run "locust". Once you’ve started Locust, open up a browser and point it to http://localhost:8089. You will be greeted with something like this: