in functions/main.py [0:0]
def process_image(data, context):
file = data
# Call Vision API and get response
vision_client = vision.ImageAnnotatorClient()
image = types.Image()
image.source.image_uri = 'gs://' + file['bucket'] + '/' + file['name']
response = vision_client.label_detection(image=image)
# Process labels from Vision API
labels = response.label_annotations
labels_array = []
for label in labels:
labels_array.append(label.description)
# Add data to Cloud Firestore database
db = firestore.Client()
doc_ref = db.collection(u'photos').document(file['name'])
doc_ref.set({
u'labelsDetected': labels_array
})