auth(function (err, authClient) {
    if (err) {
      return callback(err);
    }
    var hostedmodels = google.prediction({
      version: 'v1.6',
      auth: authClient
    }).hostedmodels;
    // Predict the sentiment for the provided phrase
    hostedmodels.predict({
      // Project id used for this sample
      project: '414649711441',
      hostedModelName: 'sample.sentiment',
      resource: {
        input: {
          // Predict sentiment of the provided phrase
          csvInstance: phrase.split(/\s/gi)
        }
      }
    }, function (err, prediction) {
      if (err) {
        return callback(err);
      }

      // Received prediction result
      console.log('Sentiment for "' + phrase + '": ' + prediction.outputLabel);
      callback(null, prediction);
    });
  });
Beispiel #2
0
    constructor() {
        this.isAuthorized = false;
        this.authTokens = null;

        this.authClient = new google.auth.JWT(
            config.google.clientEmail,
            null,
            config.google.privateKey,
            "https://www.googleapis.com/auth/prediction"
        );

        this.prediction = google.prediction({
            version: "v1.6"
        });
    }
// Run this script: node script-3-3D.js image_path=\"Image_1.bmp\" text=\"VladIonescu\" font=\"OpenSans-Regular.ttf\" font_size=50 pos_x=250 pos_y=250
// Note: it requires node.js and conventjs installed (npm install convnetjs).

var fs = require('fs');
var exec = require('child_process').exec;
var google = require('googleapis');
var prediction = google.prediction('v1.6');

var PREDICTIONS_ENABLED = true;

if (!PREDICTIONS_ENABLED) {
    console.log("Error: predictions are disabled! Set PREDICTIONS_ENABLED flag to true.");
    
} else {
    // Evaluate arguments.
    var image_path;
    var text;
    var font;
    var font_size;
    var pos_x;
    var pos_y;
    var H1, S1, B1, H2, S2, B2, H3, S3, B3;
    var predicted_H, predicted_S, predicted_B;

    process.argv.forEach(function (val, index, array) {
        if (index > 1) {
            eval(val);
        }
    });
    
    // Run Octave script to obtain the H, S and B of three dominant colors.
var google = require('googleapis');
var trainedModels = google.prediction('v1.6').trainedmodels;

var dep = require("../dep");
var config = require("../config")
auth = dep.auth;

// Module Exports
module.exports = {
    checkStatus: checkStatus()
}


function check(callback) {

    auth(google, function(err, authClient) {
        if (err) {
            callback({
                err: err
            })
        }
        trainedModels.get({
            auth: authClient, //required
            project: config.sample1.projectID,
            id: config.sample1.requestBody.id
        }, function(err, data) {
            if (err) {
                callback({
                    err: err
                })
            } else {
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START predict]
var google = require('googleapis');
var hostedmodels = google.prediction('v1.6').hostedmodels;

function auth(callback) {
  google.auth.getApplicationDefault(function (err, authClient) {
    if (err) {
      return callback(err);
    }

    // The createScopedRequired method returns true when running on GAE or a
    // local developer machine. In that case, the desired scopes must be passed
    // in manually. When the code is  running in GCE or a Managed VM, the scopes
    // are pulled from the GCE metadata server.
    // See https://cloud.google.com/compute/docs/authentication for more
    // information.
    if (authClient.createScopedRequired && authClient.createScopedRequired()) {
      // Scopes can be specified either as an array or as a single,