Skip to content

Instantly share code, notes, and snippets.

@alexandre-bruffa
Last active July 7, 2023 19:48
Show Gist options
  • Save alexandre-bruffa/9ad1fafffbc429a7ded5a5a4175074a9 to your computer and use it in GitHub Desktop.
Save alexandre-bruffa/9ad1fafffbc429a7ded5a5a4175074a9 to your computer and use it in GitHub Desktop.
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