Skip to content

Latest commit

 

History

History
126 lines (78 loc) · 5.23 KB

README.md

File metadata and controls

126 lines (78 loc) · 5.23 KB

Google Cloud Vision API Sample

This sample demonstrates how to use the following APIs:

This sample application will be deployed on the App Engine Standard Environment. The frontend of the application displays information retrieved from the Vision API including label detection, face detection, and web entity detection.

Setup

Create a Project

  1. Create a project with the Google Cloud Platform Console Cloud Resource Manager.
    1. Make note of your project ID, which may be different than your project name.
    2. Make sure to Enable Billing for your project.

Enable the APIs

  1. Go to the Google Cloud Platform console.
  2. Click the button in the top left, select APIs & Services.
  3. Click 'Enable APIs and Services' at the top, search for Vision.
  4. Click the first result, then click the Enable button.
  5. Enable the Cloud Firestore API the same way. (If it says 'Manage' when you visit its page, it's already enabled)
  6. Enable the Google Cloud Storage JSON API as well. (If it says 'Manage' when you visit its page, it's already enabled)

Create a Cloud Storage Bucket

Create a Cloud Storage bucket.

  1. Go to the Google Cloud Platform console.
  2. Click the button in the top left, scroll down and select Storage.
  3. Click Create Bucket at the top.
  4. Name your bucket the same as your project ID.

Set the CLOUD_STORAGE_BUCKET environment variable to your Cloud Storage bucket using command line:

export CLOUD_STORAGE_BUCKET=INSERT_NAME_OF_YOUR_BUCKET

Set up Cloud Firestore

Set up your Cloud Firestore database.

  1. Go to the Google Cloud Platform console.
  2. Click the button in the top left, and scroll down and select Firestore.
  3. In the 'Select a database service' screen, choose Cloud Firestore in Native mode.
  4. Select a Cloud Firestore location that is close to you geographically and click Create Database.

Download the Google Cloud SDK command line tool, also known as gcloud.

Initialize gcloud, selecting your Google account and project ID:

gcloud init

Getting the sample code

Run the following command to clone the Github repository:

git clone https://github.com/GoogleCloudPlatform/hackathon-toolkit.git

Change directory to the sample code location:

cd hackathon-toolkit/vision

Authentication

Set up a service account.

  1. Visit the Google Cloud Platform console.
  2. Search Service Accounts on the top search bar.
  3. Click on Service accounts, and click the Create Service Account button at the top.
  4. Give your service account a name and click CREATE.
    1. For service account permissions, click Select a role and choose Project > Owner.
    2. Click CONTINUE.
    3. Click CREATE KEY, and click CREATE to download a JSON service account key to your computer.
    4. Click DONE to finish creating your service account.
  5. Save the generated service account key JSON file to somewhere on your computer and rename it to key.json.

Set the GOOGLE_APPLICATION_CREDENTIALS variable to point to the service account key location:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service/account/key.json

Running Locally

Set up your virtual environment:

virtualenv env

Note: If you do not already have virtualenv installed, run 'sudo easy_install pip' and then 'pip install virtualenv'.

Enter your virtual environment:

source env/bin/activate

Install dependencies:

pip install -r requirements.txt

Test your application locally:

python main.py

Visit localhost:8080 to view your application running locally. Press Control-C from command line when you are finished.

When you are ready to leave your virtual environment:

deactivate

Deploying to App Engine

Before deploying, open the app.yaml file and replace YOUR_CLOUD_STORAGE_BUCKET with the name of your Cloud Storage bucket. This allows your code to access the appropriate environment variable when it is deployed.

Deploy your application to App Engine (should take <1 minute). When prompted to choose a region, choose the one that is closest to you geographically.

gcloud app deploy

Further Reference