Name: lambda-refarch-imagemoderationchatbot
Owner: Amazon Web Services - Labs
Owner: AWS Samples
Description: The Image Moderator Chatbot serverless reference architecture demonstrates how to leverage Amazon Rekognition's image moderation deep learning feature to automatically remove messages containing explicit or suggestive images from channels of popular chat apps using Amazon API Gateway, AWS Lambda, and Amazon Rekognition.
Created: 2017-07-25 19:13:29.0
Updated: 2018-01-10 21:35:44.0
Pushed: 2017-11-30 18:21:21.0
Size: 2541
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Administrators of large channels in popular chat apps can struggle to protect their users from trolls posting explicit or suggestive images. The Image Moderation Chatbot Serverless reference architecture solves this problem by using Amazon API Gateway, AWS Lambda, and Amazon Rekognition's image moderation deep learning feature to check images contained in messages posted to channels for explicit or suggestive content. Image moderation provides a hierarchical list of labels for each image with confidence scores to enable fine-grained control over what images to allow. Images found to contain explicit or suggestive content labels above a minimum confidence interval are automatically removed by the bot, and a message explaining the removal is posted by the bot to the originating channel.
This example is intended to work with Slack, but could also be modified to work with other popular chat apps such as Facebook Messenger.
This repository contains sample code for all the Lambda functions depicted in the diagram below as well as an AWS CloudFormation template for creating the functions and related resources.
To see some of the other powerful features of Amazon Rekognition in action check out the Image Recognition and Processing Backend Serverless reference architecture
First make sure you're logged in to Slack, then follow these instructions to prep your bot:
Basic Information
tab under Settings
take note of the Verification Token
as it will be required laterOAuth & Permissions
tab under Features
Permissions Scopes
section add the following permission scopesSave Changes
Install App to Team
then Authorize
then note the OAuth Access Token
as it will be required laterThe backend infrastructure can be deployed in US West - Oregon (us-west-2) using the provided CloudFormation template. Click Launch Stack to launch the template in the US West - Oregon (us-west-2) region in your account:
(On the last page of the wizard, make sure to:
If you would like to deploy the template manually, you need a S3 bucket in the target region, and then package the Lambda functions into that S3 bucket by using the aws cloudformation package
utility.
Set environment variables for later commands to use:
CKET=[REPLACE_WITH_YOUR_BUCKET]
ON=[REPLACE_WITH_YOUR_REGION]
KNAME=[REPLACE_WITH_DESIRED_NAME]
EN=[REPLACE_WITH_VERIFICATION_TOKEN]
EN=[REPLACE_WITH_OAUTH_ACCESS_TOKEN]
Then go to the cloudformation
folder and use the aws cloudformation package
utility
loudformation
cloudformation package --region $REGION --s3-bucket $S3BUCKET --template image_moderator.serverless.yaml --output-template-file image_moderator.output.yaml
Last, deploy the stack with the resulting yaml (image_moderator.output.yaml
) through the CloudFormation Console or command line:
cloudformation deploy --region $REGION --template-file image_moderator.output.yaml --stack-name $STACKNAME --capabilities CAPABILITY_NAMED_IAM --parameter-overrides VerificationToken=$VTOKEN AccessToken=$ATOKEN
RequestURL
output from the created stack as it will be required laterEvent Subscriptions
tab under Features
and enable eventsRequest URL
field enter the RequestURL
value noted earlierAdd Team Event
and select message.channels
Save Changes
To test the example open your Slack bot and attempt to upload the sample images from the Amazon Rekognition console demo, which can be downloaded from the links below:
To remove all resources created by this example, do the following:
The following sections explain all of the resources created by the CloudFormation template provided with this example.
This reference architecture sample is licensed under Apache 2.0.