-
-
Save alexandre-bruffa/9ad1fafffbc429a7ded5a5a4175074a9 to your computer and use it in GitHub Desktop.
This file contains 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 json | |
import boto3 | |
def lambda_handler(event, context): | |
bucket = "censorimagesbucket" | |
filename = event["filename"] | |
moderation_labels = ["Explicit Nudity", "Suggestive", "Violence", "Visually Disturbing", "Rude Gestures", "Drugs", "Tobacco", "Alcohol", "Gambling", "Hate Symbols"] | |
# Call Rekognition | |
rekognition_client = boto3.client('rekognition') | |
response = rekognition_client.detect_moderation_labels(Image={ | |
"S3Object": { | |
"Bucket": bucket, | |
"Name": filename, | |
} | |
}) | |
# Check if moderation is needed | |
labels = response['ModerationLabels'] | |
moderation = any(((label["ParentName"] or label['Name'])in moderation_labels) for label in labels) | |
# Return if moderation is needed | |
return { | |
"moderation": moderation | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment