In [ ]:
# Uncomment as needed
# BigML
#rm bigml.bashrc
# Google
#rm gpred.bashrc
#rm gpred_oauth.json
#rm gpred_service_account.json
Your BigML username and API key can be found at https://bigml.com/account/apikey. Fill them in in the first two lines below (between the quotation marks.
In [ ]:
export user=""
export key=""
echo "export BIGML_USERNAME=$user" >> bigml.bashrc
echo "export BIGML_API_KEY=$key" >> bigml.bashrc
echo "export BIGML_AUTH=username="$user"\;api_key="$key"" >> bigml.bashrc
Create a new project in the Google Developers Console or use an existing one. Activate billing (enter your Credit Card information, even though there's free quota — the paid subscription is $10/month FYI).
Fill in your project number and your project ID in the first two lines below.
In [ ]:
export google_project_number=""
export google_project_id=""
echo "export GPRED_PROJECT_NUMBER=$google_project_number" >> gpred.bashrc
echo "export GPRED_PROJECT_ID=$google_project_id" >> gpred.bashrc
Use link in output from block below to create a new service account and to get the json credentials file:
In [ ]:
echo "https://console.developers.google.com/project/$google_project_number/apiui/credential/serviceaccount"
In [ ]:
echo "Once you have the json credentials file, move it to `pwd`/gpred_service_account.json"
All we need to do is to create a boto config file for later use in gspythonlibrary.
In [ ]:
FOO="[Credentials]
gs_service_key_file = `pwd`/gpred_service_account.json
[Boto]
https_validate_certificates = True
[GSUtil]
content_language = en
default_api_version = 2
default_project_id = $google_project_id
[OAuth2]
"
printf '%s\n' "$FOO" > ~/.boto
chmod 0400 ~/.boto
In [ ]:
echo "https://console.developers.google.com/project/$google_project_number/apiui/apis/library"
The line below creates oauth tokens from the service account credentials, which we we will later use to authenticate and initialize the Google Prediction API wrapper.
In [ ]:
python create_gpred_oauth.py
View tokens file:
In [ ]:
export GPRED_OAUTH_FILE=`pwd`/gpred_oauth.json
echo "export GPRED_OAUTH_FILE=`pwd`/gpred_oauth.json" >> gpred.bashrc
cat $GPRED_OAUTH_FILE
In [ ]:
cat bigml.bashrc >> ~/.bashrc
cat gpred.bashrc >> ~/.bashrc
Go back to the command line and run
source ~/.bashrc
Restart kernel in other Bash notebooks that are already opened, in order to get the .bashrc changes
Using environment variables from jupyter notebooks isn't straightforward because service strips all environment variables but TERM, PATH and LANG. I haven't found a way to automatically change this yet, but the workaround is to edit the script in /etc/init/jupyter.conf to add the contents of bigml.bashrc and gpred.bashrc just before these two lines:
echo 621 > /var/run/ipython_start.pid
exec jupyter-notebook --config='/root/.ipython/profile_nbserver/ipython_config.py'
You should then close all notebooks and restart jupyter with the following command executed as root:
service jupyter restart