Skip to content

Commit d6dab95

Browse files
committed
full working hotdog analyzer
1 parent 4320b62 commit d6dab95

File tree

12 files changed

+6841
-255
lines changed

12 files changed

+6841
-255
lines changed

functions/src/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,36 @@ admin.initializeApp(functions.config().firebase);
99
import * as vision from '@google-cloud/vision';
1010
const visionClient = new vision.ImageAnnotatorClient();
1111

12+
// Dedicated bucket for cloud function invocation
1213
const bucketName = 'firestarter-96e46-vision';
1314

14-
15-
1615
export const imageTagger = functions.storage
1716

1817
.bucket(bucketName)
1918
.object()
2019
.onChange( async event => {
2120

21+
// File data
2222
const object = event.data;
2323
const filePath = object.name;
2424

25+
// Location of saved file in bucket
2526
const imageUri = `gs://${bucketName}/${filePath}`;
2627

28+
// Firestore docID === file name
2729
const docId = filePath.split('.jpg')[0];
28-
console.log(2, docId)
30+
2931
const docRef = admin.firestore().collection('photos').doc(docId);
30-
3132

33+
// Await the cloud vision response
3234
const results = await visionClient.labelDetection(imageUri);
33-
const labels = results[0].labelAnnotations.map(obj => obj.description);
3435

35-
console.log(3, results)
36+
// Map the data to desired format
37+
const labels = results[0].labelAnnotations.map(obj => obj.description);
38+
const hotdog = labels.includes('hot dog')
3639

3740

38-
return docRef.set({ labels })
41+
return docRef.set({ hotdog, labels })
3942

4043

4144
});

0 commit comments

Comments
 (0)