Created
July 18, 2019 12:11
-
-
Save DataSolveProblems/d042aa009c08c8ddd6a04df29106aad5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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