Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataSolveProblems/851b37841d6b12eb86f853666cbcbc91 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/851b37841d6b12eb86f853666cbcbc91 to your computer and use it in GitHub Desktop.
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