Manually review text

更新时间:
复制 MD 格式

This topic describes how to use the Python software development kit (SDK) to manually review text.

Feature description

If the results of machine-assisted moderation do not meet your expectations, call the text manual review API. For more information about the parameters, see the Text manual review API documentation.

You must use the Content Moderation endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.

Prerequisites

  • Python dependencies are installed. For more information, see Installation.

    Note

    You must use the required Python version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.

  • The Extension.Uploader utility class is downloaded and imported into your project.

Submit a video manual review task

# coding=utf-8
import uuid

from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import TextAsyncManualScanRequest
import json

# Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
# Common ways to get environment variables:
# Get the AccessKey ID of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Get the AccessKey secret of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Your AccessKey ID", "Your AccessKey secret", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = TextAsyncManualScanRequest.TextAsyncManualScanRequest()
request.set_accept_format('JSON')

# The callback and seed parameters are used for callback notifications. They are optional.
request.set_content(
    json.dumps(
        {"tasks": [{"dataId": "Data ID", "content": "Text to be scanned"}], "callback": "Webhook address",
         "seed": "Random string"}))

try:
    response = clt.do_action_with_exception(request)
    print response
except Exception, err:
    print err.__str__()

Query the results of a text manual review task

# coding=utf-8

from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import TextAsyncManualScanResultsRequest
import json

# Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
# Common ways to get environment variables:
# Get the AccessKey ID of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Get the AccessKey secret of a RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("Your AccessKey ID", "Your AccessKey secret", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = TextAsyncManualScanResultsRequest.TextAsyncManualScanResultsRequest()
request.set_accept_format('JSON')

request.set_content(json.dumps(["Text manual review task ID"]))

try:
    response = clt.do_action_with_exception(request)
    print response
except Exception, err:
    print err.__str__()