Amazon Rekognition leverages scalable deep learning technology in order to perform image and video analysis without machine learning expertise. Rekognition can be used to detect images that are suggestive or visually disturbing, indicate violence, or contain explict nudity for content moderation.
Curently, Unishop users can upload any image when adding a unicorn to the inventory. We want to moderate the content that appears in our inventory in order to prevent inappropriate or sensitive images from appearing on our website.
Following the repository/service pattern, we have pre-created the RekognitionService interface and the RekognitionService class. However, we have not implemented the Rekognition logic.
Go to your developer desktop. In the Solution Explorer of Visual Studio, right click the “InventoryService” project and select “Manage NuGet Packages”.
At the top, select the “Browse” tab. Search for Rekognition, click “AWSSDK.Rekognition”, and then click “Install”. A pop-up wil appear telling you that you are about to make changes to the solution. Click “OK”.
In the Solution Explorer, expand the “Service” folder and open the “RekognitionService.cs” file.
Uncomment the following using statements to the top of the “RekognitionService.cs” file:
Uncomment the definition of “GetContentModerationLabels()” function:
In the Solution Explorer, expand the “Controllers” folder, and open UnicornController.cs. Scroll down to the “CreateUnicorn()” function, and uncomment the function call to the “GetContentModerationLabels()” function that you just visited in last step.
Rebuild the project before you redeploy the inventory service. Make sure the build succeed.
Redeployment will be largely the same with the deployment process in the part 1 of Containerized Inventory Service. In the solution explorer, right-click the “InventoryService” and select “Publish Container to AWS…” In the wizard, simply click “Next” through the entire interaction since the settings have been saved.
After the redeployment, you may notice that the tasks you deployed in previous steps and created by auto-scaling are not instantly stopped. This is because the previous version will be retained for some time before being stopped in the process of updating.
By default, API Gateway will always return 200 to the frontend even if it receives a 500 response from the backend. To disable this, we need to enable HTTP proxy integration for the POST method under “/unicorn” resource. When you tick this option, API Gateway will send the response from the backend directly to the frontend without any processing.
In your AWS Management Console, navigate to the API Gateway.
Click the POST method under “/unicorn” and click “Integration Request.”
Tick “Use HTTP Proxy integration.”
Save this image on your developer desktop:
In your developer desktop, open a browser and direct yourself to app.unishop.local. Log in and click the “Upload” button in the top nav bar.
We will try uploading a gun to our inventory. Enter the following:
Unicorn name: Enter UnicornGun
Description: Enter a unicorn gun
Price: Enter 100
Upload Image: Select the image of the gun you downloaded.
Click “Upload”. As you can see, you were not able add this unicorn to the inventory as Rekognition detected “Violence” in the uploaded image.