Deploying ML model in Google Cloud Platform (GCP)

Deploying ML model in Google Cloud Platform (GCP)

Deploying ML model in Google Cloud Platform (GCP)

We had seen the deployment in heroku in our previous article. Let us see the deployment of machine learning model in google cloud platform.


After creating our flask application, Our next step is to expose our model to the user i.e, deploying it in cloud platform. To do it, our first step is to Install Google Cloud Installer in your system. Google Cloud SDK is a set of tools that you can use to manage resources and applications hosted on Google Cloud. These tools include the gcloud, gsutil, and bq command-line tools.

Create requirements.txt file

To get all the dependencies for the virtual environment, which is required for our project.
Go to project folder, activate your virtual environment after that run below command.

pip freeze > requirements.txt

pip freeze command will create requirements.txt file in project root folder. You can open requirements.txt and see required modules.

Create project in Google Cloud Platform

Login to https://console.cloud.google.com/
Click on menu icon -> IAM & Admin -> Manage Resources.

After clicking on manage resources, Click on “CREATE PROJECT” -> Enter project name -> click on CREATE.
Now the project is successfully created.

What is App Engine?

App Engine standard environment makes it easy to build and deploy an application that runs reliably under heavy load and with large amounts of data.
Your application runs within its own secure, reliable environment that is independent of the hardware, operating system, or physical location of the server.
We can view created project in App Engine.

Create app.yaml Configuration File in project root folder

We need to configure App Engine app’s settings in the app.yaml file. The app.yaml file also contains information about your app’s code, such as the runtime and the latest version identifier.
Each service in your app will have its own app.yaml file, which acts as a descriptor for its deployment.
Generally, app.yaml file requires only the runtime element for a simple Python 3 app in the standard environment, like:
runtime: python38 # or python37 for Python 3.7

Create app.yaml file in root project folder and write following code in that:

runtime: python38

Deploying the Flask application:

Initialize Google Cloud in your project.
“gcloud init” command to perform initial setup tasks.

gcloud init performs the following setup steps:

1. Authorizes Cloud SDK tools to use your user account credentials to access Google Cloud, or lets you select an account if you have previously authorized access
2. Sets up a Cloud SDK configuration and sets a base set of properties, including the active account from the step above, the current project, and if applicable, the default Google Compute Engine region and zone.

Open Google Cloud SDK Shell in your system, go to project folder and type below command

F:
cd F:\python-projects\flask-projects\sales-app
gcloud init

It will ask to “Pick Configuration to use” -> Choose option 1 if you are already logged in.
Otherwise type 2 to Log in with a new account.

You need type your project number which you want to deploy.

Deploy the application

Deploy your application to App Engine using the “gcloud app deploy” command.

gcloud app deploy --project name

It will ask to “Choose a region you want your App Engine application”. You can choose according to your choice.It will take some time to deploy, till the time you need to wait.

And finally our project is deployed in google cloud platform.

Hope you enjoyed learning this article.Thank you.

0 Response to "Deploying ML model in Google Cloud Platform (GCP)"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel