Last active
September 24, 2020 14:33
-
-
Save pepetox/127e7c7303eb867265c6d8c4adf5b500 to your computer and use it in GitHub Desktop.
Workshop OpenSpace 2020 ML - Step 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//gcloud functions deploy getData --runtime nodejs12 --trigger-resource mysandoxbucket --trigger-event google.storage.object.finalize --project my-sandbox-project | |
exports.getData = async (file, context) => { | |
//set the vars | |
const bucketName = "mysandoxbucket"; | |
//load the dependences | |
const vision = require('@google-cloud/vision'); | |
console.log(`Data for ${file.name}:`); | |
//Ask for labels of image | |
const client = new vision.ImageAnnotatorClient(); | |
const [resultLabels] = await client.labelDetection(`gs://${bucketName}/${file.name}`); | |
const labels = resultLabels.labelAnnotations; | |
let labelsDetected = [] | |
labels.forEach(label => labelsDetected.push(label.description)); | |
console.log("Labels", JSON.stringify(labelsDetected)); | |
//Ask for face detection | |
const [resultFaces] = await client.faceDetection(`gs://${bucketName}/${file.name}`); | |
const faces = resultFaces.faceAnnotations; | |
console.log("Faces", JSON.stringify(faces)); | |
//ask safe content | |
const [resultSafe] = await client.safeSearchDetection(`gs://${bucketName}/${file.name}`); | |
const detections = resultSafe.safeSearchAnnotation; | |
console.log("Safe", JSON.stringify(detections)); | |
//OCR | |
const [resultOCR] = await client.documentTextDetection(`gs://${bucketName}/${file.name}`); | |
const fullTextAnnotation = resultOCR.fullTextAnnotation; | |
if(fullTextAnnotation&&fullTextAnnotation.text){ | |
console.log("OCR", JSON.stringify(fullTextAnnotation.text)); | |
} | |
console.log("finish"); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "taller-openspace", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@google-cloud/vision": "^2.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment