Face Detection Python Flask Web application in Google Cloud

Patelchintan
4 min readJul 26, 2020

In real world scenario ML is a very useful technology. So, For creating a Machine learning model sometime we have some major resources so we can make model work. Suppose we have to load a machine learning model which requires more computing more CPUs. So, we can not afford sometime.

So, Cloud Technology is one of the way to make our work easy in terms of money, time and much more. Today’s world there are many service providers are there for cloud resources such like Google Cloud, AWS, IBM, Microsoft Azure, etc.

Google Cloud ML Engine

Here, we are going to cover topic related to a face detection machine learning model on Google cloud.

First of all, In this blog we are discuss about which services used by this web application on Google Cloud. So, App Engine Flexible, Datastore, Google Cloud Storage and Google Cloud vision APIs.

In this article, you will explain how to deploy a Python Flask web application to the App Engine Flexible environment. The example application allows a user to upload a photo of a person’s face and learn how likely it is that the person is happy. The application uses Google Cloud APIs for Vision, Storage, and Datastore.

First of all we have to create our project on google cloud platform so we can perform our task on that. A project have different services like App engine, IAM, security, compute engine, etc.

Home Page of Google cloud Platform

here, as we can see that a project is created and also you can see at the left some services which is provided by Google cloud. In this you can get each details like billing, google cloud platform status or new updates of google cloud, etc.

After complete this step you have to enabled Vision APIs, Datastore and storage. After enabling this things you have to Authenticate your APIs request so you can perform some task:

For authenticate:

  1. export project id
  2. choose role as owner
  3. crate a service account and it’s key

After this you are ready to go !!

Now, You have to test your app locally in virtual environment. so here is some command that you have to run in your cloud shell:

virtualenv -p python3 env

source env/bin/activate

pip install -r requirements.txt

In this requirement.txt file you have all requirement of tool with version.

After creation of virtual environment you have to create a app engine instance.So, we can create our machine learning model into app.

Google cloud app engine
gcloud app create — command and output is successfully created app engine instance

Now, we store dataset into storage so we have a storage bucket.

google cloud storage
Storage bucket is created.
Flask for web development

Here we go with some code that is created in flask so we can make our machine learning model on web. main.py file:

Some code of main.py file

That’s it !!

For apply this code output we have to create a html kind of code in this scenario: Homepage.html file:

Homepage.html for web page

Now we have to run it.

We ready with output:

Output look like.

--

--