in object-localization/code/main.py [0:0]
def detect_safe_search_uri(uri):
"""Detects unsafe features in the file located in Google Cloud Storage or
on the Web."""
from google.cloud import vision
client = vision.ImageAnnotatorClient()
image = vision.Image()
image.source.image_uri = uri
response = client.safe_search_detection(image=image)
safe = response.safe_search_annotation
# Names of likelihood from google.cloud.vision.enums
likelihood_name = (
"UNKNOWN",
"VERY_UNLIKELY",
"UNLIKELY",
"POSSIBLE",
"LIKELY",
"VERY_LIKELY",
)
if response.error.message:
raise Exception(
"{}\nFor more info on error messages, check: "
"https://cloud.google.com/apis/design/errors".format(
response.error.message)
)
safe_search = {
"adult": likelihood_name[safe.adult],
"medical": likelihood_name[safe.medical],
"spoofed": likelihood_name[safe.spoof],
"violence": likelihood_name[safe.violence],
"racy": likelihood_name[safe.racy]
}
return safe_search