This script set refer google api client sample in Python, you can see original codes here google-api-python-client/samples/prediction .
prediction.py
is a sample code using OAuth credentials (JSON) link to your personal information on your Google Developer Console. prediction_service.py
is also same, but it uses Service Account Credentials instead of personal OAuth2 credentials. 2nd one is to avoid OAuth2 browser authentication such as Two Legged OAuth
.
- Python 2.7
- Virtualenv
$ virtualenv venv
$ source venv/bin/activate
(venv)$ mkdir lib
(venv)$ pip install -t lib -r requirements.txt
- Create a project from Developer Console
- Enable 2 API which are Prediction API and Cloud Storage API.
- Create a OAuth2 credentials and populates it with name
client_secrets.json
. - Create a ServiceAccount.
- Download credentials as.
<your-project-name>-xxxx.json
to place same level on yourclient_secrets.json
- Upload language_id.txt to your Cloud Storage
$ python prediction.py "bucket/object" "model_id" "project_id"
$ python prediction_service.py "bucket/object" "model_id" "project_id" "my-xxxxx.json"