All Products
Search
Document Center

ApsaraVideo VOD:Video AI

Last Updated:Aug 22, 2023

This topic provides examples on how to use the API operations of the video AI module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to submit or query AI jobs, set a default AI template, and query the default AI template. You can also create, delete, modify, and query AI templates.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

Before you can use the SDK, initialize a client. For more information, see Initialization.

Submit an AI job

You can call the SubmitAIJob operation to submit an AI job.

Query AI jobs

You can call the ListAIJob operation to query AI jobs.

Create an AI template

You can call the AddAITemplate operation to create an AI template.

For more information about the request and response parameters of this operation, see AddAITemplate. Sample code:

from aliyunsdkvod.request.v20170321 import AddAITemplateRequest
def add_ai_template(clt):
    request = AddAITemplateRequest.AddAITemplateRequest()

    # The template type. An automated review template is used as an example.
    request.set_TemplateType('AIMediaAudit')
    # The name of the template.
    request.set_TemplateName('My AI Template')
    # The detailed configurations of the template.
    auditItem = ['terrorism', 'porn']
    auditRange = ['video', 'image-cover', 'text-title']
    auditContent = ['screen']
    templateConfig = {'AuditItem': auditItem, 'AuditRange': auditRange, 'AuditContent': auditContent,
                      'AuditAutoBlock': 'no'}
    request.set_TemplateConfig(json.dumps(templateConfig))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = add_ai_template(clt)
    print(res['TemplateId'])
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Modify an AI template

You can call the UpdateAITemplate operation to modify an AI template.

For more information about the request and response parameters of this operation, see UpdateAITemplate.

Sample code:

from aliyunsdkvod.request.v20170321 import UpdateAITemplateRequest
def update_ai_template(clt):
    request = UpdateAITemplateRequest.UpdateAITemplateRequest()
    # The ID of the template.
    request.set_TemplateId('<TemplateId>')
    # The name of the template.
    request.set_TemplateName('New AI Template Name')
    # The detailed configurations of the template.
    auditItem = ['terrorism', 'porn']
    auditRange = ['video', 'image-cover']
    auditContent = ['screen']
    templateConfig = {'AuditItem': auditItem, 'AuditRange': auditRange, 'AuditContent': auditContent,
                      'AuditAutoBlock': 'yes'}
    request.set_TemplateConfig(json.dumps(templateConfig))

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = update_ai_template(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query an AI template

You can call the GetAITemplate operation to query information about an AI template.

For more information about the request and response parameters of this operation, see GetAITemplate. Sample code:

Query AI templates

You can call the ListAITemplate operation to query AI templates.

For more information about the request and response parameters of this operation, see ListAITemplate. Sample code:

Set a default AI template

You can call the SetDefaultAITemplate operation to set a default AI template.

For more information about the request and response parameters of this operation, see SetDefaultAITemplate. Sample code:

Query the default AI template

You can call the GetDefaultAITemplate operation to query details of the default AI template.

For more information about the request and response parameters of this operation, see GetDefaultAITemplate. Sample code:

Delete an AI template

You can call the DeleteAITemplate operation to delete an AI template.