Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Created July 18, 2019 12:11
Show Gist options
  • Save DataSolveProblems/d042aa009c08c8ddd6a04df29106aad5 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/d042aa009c08c8ddd6a04df29106aad5 to your computer and use it in GitHub Desktop.
import os
import io
from google.cloud import vision
import pandas as pd
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r"GoogleCloudDemo.json"
client = vision.ImageAnnotatorClient()
file_name = 'Chicago.jpg'
image_path = f'.\VisionAPI\Images\{file_name}'
with io.open(image_path, 'rb') as image_file:
content = image_file.read()
# construct an iamge instance
image = vision.types.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
df = pd.DataFrame(columns=['description', 'score', 'topicality'])
for label in labels:
df = df.append(
dict(
description=label.description,
score=label.score,
topicality=label.topicality
), ignore_index=True)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment