Skip to content

Update method for safe search detection #533

@aliciawilliams

Description

@aliciawilliams

The method for safe search detection has been changed. I made a few changes to the code in order to complete this tutorial: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/functions/imagemagick/index.js. This is my first Github contribution (ever), so let me know if/how to proceed.

  1. Added new const request immediately after the const file declaration.
const request = {
    source: {
      imageUri: `gs://${object.bucket}/${file.name}`
    }
  };
  1. Changed method name in line 44 from vision.detectSafeSearch(file) to vision.safeSearchDetection(request)
  2. Updated the evaluation for determining an inappropriate image to account for new format of JSON response. Now looks for adult and violence outcomes of VERY_LIKELY or LIKELY.
.then((results) => {
      const detections = results[0].safeSearchAnnotation;
      if (detections.adult == 'VERY_LIKELY' || detections.adult == 'LIKELY' || detections.violence == 'VERY_LIKELY' || detections.violence == 'LIKELY') {
        console.log(`The image ${file.name} has been detected as inappropriate.`);
        return blurImage(file);
      } else {
        console.log(`The image ${file.name} has been detected as OK.`);
      }
    });
```javascript

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions