Created
July 24, 2019 10:43
-
-
Save DataSolveProblems/851b37841d6b12eb86f853666cbcbc91 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 io, os | |
from google.cloud import vision | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r"GoogleCloudDemo_ServiceAcct_Token.json" | |
client = vision.ImageAnnotatorClient() | |
file_name = 'cat.jpg' | |
image_path = os.path.join('.\images', file_name) | |
with io.open(image_path, 'rb') as image_file: | |
content = image_file.read() | |
image = vision.types.Image(content=content) | |
response = client.safe_search_detection(image=image) | |
safe_search = response.safe_search_annotation | |
likelihood = ('Unknown', 'Very Unlikely', 'Unlikely', | |
'Possible', 'Likely', 'Very Likely') | |
print('adult: {0}'.format(likelihood[safe_search.adult])) | |
print('spoof: {0}'.format(likelihood[safe_search.spoof])) | |
print('medical: {0}'.format(likelihood[safe_search.medical])) | |
print('violence: {0}'.format(likelihood[safe_search.violence])) | |
print('racy: {0}'.format(likelihood[safe_search.racy])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment