How to use the @google-cloud/automl.AutoMlClient function in @google-cloud/automl

To help you get started, we’ve selected a few @google-cloud/automl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-automl / samples / vision / object-detection / list-models.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_list_models]
  /**
   * Demonstrates using the AutoML client to list all models.
   * 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 filter_ = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionModelMetadata:*";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function listModels() {
    // A resource that represents Google Cloud Platform location.
    const projectLocation = automlClient.locationPath(projectId, computeRegion);

    // List all the models available in the region by applying filter.
    const [response] = await automlClient.listModels({
      parent: projectLocation,
      filter: filter,
    });
    console.log(`List of models:`);
    for (const model of response) {
      console.log(`\nModel name: ${model.name}`);
      console.log(`Model Id: ${model.name.split(`/`).pop(-1)}`);
      console.log(`Model display name: ${model.displayName}`);
      console.log(`Dataset Id: ${model.datasetId}`);
github googleapis / nodejs-automl / samples / vision / object-detection / list-datasets.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_list_datasets]
  /**
   * Demonstrates using the AutoML client to list all Datasets.
   * 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 filter_ = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionDatasetMetadata:*";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  const util = require(`util`);

  async function listDatasets() {
    const projectLocation = automlClient.locationPath(projectId, computeRegion);

    // List all the datasets available in the region by applying filter.
    const [response] = await automlClient.listDatasets({
      parent: projectLocation,
      filter: filter,
    });
    console.log('List of datasets:');
    for (const dataset of response) {
      console.log(`\nDataset name: ${dataset.name}`);
      console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
      console.log(`Dataset display name: ${dataset.displayName}`);
      console.log(`Dataset example count: ${dataset.exampleCount}`);
github googleapis / nodejs-automl / samples / vision / object-detection / get-dataset.v1beta1.js View on Github external
datasetId = 'YOUR_DATASET_ID'
) {
  // [START automl_vision_object_detection_get_dataset]
  /**
   * Demonstrates using the AutoML client to get a dataset by ID.
   * 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 datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  const util = require(`util`);
  async function getDataset() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Get a dataset.
    const [response] = await automlClient.getDataset({name: datasetFullId});
    console.log(`Got dataset: ${response.name}`);
    console.log(`Dataset Id: ${response.name.split(`/`).pop(-1)}`);
    console.log(`Dataset display name: ${response.displayName}`);
    console.log(`Dataset example count: ${response.exampleCount}`);
    console.log(
github googleapis / nodejs-automl / samples / vision / object-detection / display-evaluation.v1beta1.js View on Github external
/**
   * Demonstrates using the AutoML client to display model evaluation.
   * 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., "IOD2122286140026257408";
  // const filter = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionModelMetadata:*";

  const math = require(`mathjs`);
  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();

  // Get the full path of the model.
  const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId);

  // List all the model evaluations in the model by applying filter.
  automlClient
    .listModelEvaluations({parent: modelFullId, filter: filter})
    .then(respond => {
      const response = respond[0];
      // Iterate through the results.
      let modelEvaluationId = ``;
      for (const element of response) {
        // There is evaluation for each class in a model and for overall model.
        // Get only the evaluation of overall model.
        if (!element.annotationSpecId) {
          modelEvaluationId = element.name.split(`/`).pop(-1);
github googleapis / nodejs-automl / samples / vision / object-detection / import-data.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_import_data]
  /**
   * Demonstrates using the AutoML client to import labeled items.
   * 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 datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";
  // const gcsPath = '[GCS_PATH]' e.g., "gs:///",
  // `.csv paths in AutoML Vision Object Detection CSV format`;
  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function importData() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Get the multiple Google Cloud Storage URIs.
    const inputUris = gcsPath.split(`,`);
    const inputConfig = {
      gcsSource: {
        inputUris: inputUris,
      },
    };
github googleapis / nodejs-automl / samples / vision / object-detection / delete-model.v1beta1.js View on Github external
modelId = 'YOUR_MODEL_ID'
) {
  // [START automl_vision_object_detection_delete_model]
  /**
   * Demonstrates using the AutoML client to delete a model.
   * 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";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function deleteModel() {
    // Get the full path of the model.
    const modelFullId = automlClient.modelPath(
      projectId,
      computeRegion,
      modelId
    );

    // Delete a model.
    const [operation] = await automlClient.deleteModel({name: modelFullId});

    const [response] = await operation.promise();
    const operationDetails = response[2];

    // Get the Model delete details.
    console.log('Model delete details:');
github googleapis / nodejs-automl / samples / vision / object-detection / undeploy-model.v1beta1.js View on Github external
modelId = 'MODEL_ID'
) {
  // [START automl_vision_object_detection_undeploy_model]
  /**
   * Demonstrates using the AutoML client to undeploy model.
   * 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., "TEN5200971474357190656";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();

  async function undeployModel() {
    // Get the full path of the model.
    const modelFullId = automlClient.modelPath(
      projectId,
      computeRegion,
      modelId
    );

    // Deploy a model with the deploy model request.
    const [operation] = await automlClient.undeployModel({name: modelFullId});
    const [response] = await operation.promise();
    for (const element of response) {
      console.log(`Undeployment Details:`);
      console.log(`\tName: ${element.name}`);
      console.log(`\tMetadata:`);
github googleapis / nodejs-automl / samples / vision / object-detection / export-data.v1beta1.js View on Github external
/**
   * Demonstrates using the AutoML client to export a dataset to a
   * Google Cloud Storage bucket.
   * 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 datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";
  // const gcsOutputUri = '[GCS_OUTPUT_URI]' e.g., "gs:///",
  // `Google Cloud Storage URI for the export directory`;

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();

  async function exportData() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Set the output URI
    const outputConfig = {
      gcsDestination: {
        outputUriPrefix: gcsOutputUri,
      },
    };
github googleapis / nodejs-translate / samples / v3beta1 / translate_translate_text_with_model_beta.js View on Github external
) {
  // [START translate_text_with_model_beta]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'YOUR_PROJECT_ID';
  // const location = 'global';
  // const modelId = 'YOUR_MODEL_ID';

  // Imports the Google Cloud Translation library
  const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
  const automl = require('@google-cloud/automl');

  // Instantiates a client
  const translationClient = new TranslationServiceClient();
  const autoMLClient = new automl.AutoMlClient();
  async function translateTextWithModel() {
    const model = autoMLClient.modelPath(projectId, location, modelId);
    // Construct request
    const request = {
      parent: translationClient.locationPath(projectId, location),
      contents: [text],
      mimeType: 'text/plain', // mime types: text/plain, text/html
      sourceLanguageCode: 'en-US',
      targetLanguageCode: 'ja',
      model: model,
    };

    // Run request
    const [response] = await translationClient.translateText(request);

    for (const translation of response.translations) {