Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// limitations under the License.
// Replace the strings below with your own project & model info
const project = 'YOUR_PROJECT_NAME';
const region = 'YOUR_PROJECT_REGION';
const automl_model = 'YOUR_AUTOML_MODEL_ID';
const sizeOf = require('image-size');
const fs = require('fs');
const exec = require('child_process').exec;
// GCP libraries
const gcs = require('@google-cloud/storage');
const gcsClient = new gcs();
const automl = require('@google-cloud/automl');
const predictionClient = new automl.PredictionServiceClient();
// Firebase libraries
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const db = admin.firestore();
admin.initializeApp(functions.config().firebase);
function resizeImg(filepath) {
return new Promise((resolve, reject) => {
exec(`convert ${filepath} -resize 600x ${filepath}`, (err) => {
if (err) {
console.error('Failed to resize image', err);
reject(err);
} else {
console.log('resized image successfully');
resolve(filepath);
async function main(
projectId,
computeRegion,
modelId,
filePath,
scoreThreshold
) {
// [START automl_quickstart]
const automl = require('@google-cloud/automl');
const fs = require('fs');
// Create client for prediction service.
const client = new automl.PredictionServiceClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`;
// const computeRegion = `region-name, e.g. "us-central1"`;
// const modelId = `id of the model, e.g. “ICN723541179344731436”`;
// const filePath = `local text file path of content to be classified, e.g. "./resources/flower.png"`;
// const scoreThreshold = `value between 0.0 and 1.0, e.g. "0.5"`;
// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
// Read the file content for prediction.
const content = fs.readFileSync(filePath, 'base64');
* Demonstrates using the AutoML client to detect the object in an image.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184";
// const filePath = '[GCS_PATH]' e.g., "/home/ubuntu/salad.jpg",
// `local text file path of content to be extracted`;
// const scoreThreshold = '[SCORE_THRESHOLD]', e.g, 0.50 ,
// `Set the score threshold for Prediction of the created model`;
//Imports the Google Cloud Automl library
const {PredictionServiceClient} = require('@google-cloud/automl').v1beta1;
// Instantiates a client
const predictionServiceClient = new PredictionServiceClient();
const fs = require(`fs`);
async function predict() {
// Get the full path of the model.
const modelFullId = predictionServiceClient.modelPath(
projectId,
computeRegion,
modelId
);
// Read the file content for prediction.
const content = fs.readFileSync(filePath, `base64`);
let params = {};
if (scoreThreshold) {
params = {