Manual review for images
Updated at:
This topic describes how to use the Python software development kit (SDK) to manually review images.
Description
If the result of machine-assisted moderation for an image does not meet your expectations, you can use the manual image review API. For more information about the parameters, see Manual image review.
You can use the API endpoint for AI Guardrails to call this SDK operation. For more information about API endpoints, see Endpoints.
Prerequisites
-
Install the required Python dependencies. For details, see Installation.
NoteInstall the exact dependency versions specified on the Installation page to prevent API call failures.
-
Download the Extension.Uploader utility class and import it into your project.
Submit a manual image review task
Sample code
# coding=utf-8
import uuid
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import ImageAsyncManualScanRequest
import json
# Note: To improve moderation performance, reuse the instantiated client and avoid creating repeated connections.
# Common methods to obtain environment variables:
# Obtain the AccessKey ID of the Resource Access Management (RAM) user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of the RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Obtain the RAM user AccessKey ID from an environment variable", "Obtain the RAM user AccessKey secret from an environment variable", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = ImageAsyncManualScanRequest.ImageAsyncManualScanRequest()
request.set_accept_format('JSON')
# The callback and seed parameters are used for callback notifications and are optional.
request.set_content(
json.dumps(
{"tasks": [{"dataId": "Data ID for moderation", "url": "URL of the image to be moderated"}], "callback": "Webhook address",
"seed": "Random string"}))
try:
response = clt.do_action_with_exception(request)
print response
except Exception, err:
print err.__str__()Query the result of a manual image review task
Sample code
# coding=utf-8
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import ImageAsyncManualScanResultsRequest
import json
# Note: To improve moderation performance, reuse the instantiated client and avoid creating repeated connections.
# Common methods to obtain environment variables:
# Obtain the AccessKey ID of the Resource Access Management (RAM) user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of the RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Obtain the RAM user AccessKey ID from an environment variable", "Obtain the RAM user AccessKey secret from an environment variable", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = ImageAsyncManualScanResultsRequest.ImageAsyncManualScanResultsRequest()
request.set_accept_format('JSON')
request.set_content(json.dumps(["Manual image review task ID"]))
try:
response = clt.do_action_with_exception(request)
print response
except Exception, err:
print err.__str__()Is this page helpful?