Smart tagging
This topic describes how to install the Python SDK V2.0 and provides sample code for using the smart tagging SDK.
Version guide
The ApsaraVideo Media Processing SDK for Python requires Python 3.6 or later. To install the Alibaba Cloud Python SDK V2.0, run the following pip command:
pip install alibabacloud_mts20140618==5.0.0Prerequisites
Before you use the SDK, you must initialize the client. For more information, see Initialization.
Submit a smart tagging job
You can call the SubmitSmarttagJob operation to submit a smart tagging job. For more information about the fields and parameters of the operation, see SubmitSmarttagJob. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
# The ID of the MPS queue.
pipeline_id='2',
# The title of the video.
title='example-title-****',
# The description of the video content.
content='example content ****',
# The additional request parameters.
params='false',
# The callback path.
notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
# The information that is passed through in the callback.
user_data='{"key":"value"}',
# The URL of the video or image file to be analyzed.
input='oss://mybucket-****/example-****.mp4',
# The ID of the template that is used to specify the analysis algorithm.
template_id='39f8e0bc005e4f309379701645f4****',
# The priority of the job in the MPS queue.
priority='5'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.submit_smarttag_job_with_options(submit_smarttag_job_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
# The ID of the MPS queue.
pipeline_id='2',
# The title of the video.
title='example-title-****',
# The description of the video content.
content='example content ****',
# The additional request parameters.
params='false',
# The callback path.
notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
# The information that is passed through in the callback.
user_data='{"key":"value"}',
# The URL of the video or image file to be analyzed.
input='oss://mybucket-****/example-****.mp4',
# The ID of the template that is used to specify the analysis algorithm.
template_id='39f8e0bc005e4f309379701645f4****',
# The priority of the job in the MPS queue.
priority='5'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.submit_smarttag_job_with_options_async(submit_smarttag_job_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:]) Query a smart tagging job
You can call the QuerySmarttagJob operation to query a smart tagging job. For more information about the fields and parameters of the operation, see QuerySmarttagJob. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
# The ID of the smart tagging job that you want to query.
job_id='39f8e0bc005e4f309379701645f4****',
# The additional request parameters.
params='{"labelResultType":"auto"}'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.query_smarttag_job_with_options(query_smarttag_job_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
# The ID of the smart tagging job that you want to query.
job_id='39f8e0bc005e4f309379701645f4****',
# The additional request parameters.
params='{"labelResultType":"auto"}'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.query_smarttag_job_with_options_async(query_smarttag_job_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Add template
You can call the AddSmarttagTemplate operation to add a template. For more information about the fields and parameters of the operation, see AddSmarttagTemplate. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
# The custom name of the template.
template_name='template-example-****',
# The industry of the file to be analyzed.
industry='common',
# The scenario in which the file is used.
scene='search',
# The analysis type.
analyse_types='ocr',
# The IDs of the face libraries that are used for recognition.
face_category_ids='celebrity',
# The parameters of the face algorithm.
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# The IDs of the object libraries that are used for recognition.
object_group_ids='general,item,weapon,animal',
# The IDs of the landmark libraries that are used for recognition.
landmark_group_ids='common',
# Specifies whether to set the template as the default template.
is_default=True,
# The annotation type.
label_type='hmi',
# The version of smart tagging.
label_version='1.0',
# In smart tagging 2.0 and 2.0-custom modes,
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# The keyword tag configuration.
keyword_config='"type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.add_smarttag_template_with_options(add_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
# The custom name of the template.
template_name='template-example-****',
# The industry of the file to be analyzed.
industry='common',
# The scenario in which the file is used.
scene='search',
# The analysis type.
analyse_types='ocr',
# The IDs of the face libraries that are used for recognition.
face_category_ids='celebrity',
# The parameters of the face algorithm.
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# The IDs of the object libraries that are used for recognition.
object_group_ids='general,item,weapon,animal',
# The IDs of the landmark libraries that are used for recognition.
landmark_group_ids='common',
# Specifies whether to set the template as the default template.
is_default=True,
# The annotation type.
label_type='hmi',
# The version of smart tagging.
label_version='1.0',
# In smart tagging 2.0 and 2.0-custom modes,
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# The keyword tag configuration.
keyword_config='"type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.add_smarttag_template_with_options_async(add_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:]) Query templates
You can call the QuerySmarttagTemplateList operation to query template information. For more information about the fields and parameters of the operation, see QuerySmarttagTemplateList. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
# The template ID.
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.query_smarttag_template_list_with_options(query_smarttag_template_list_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
# The template ID.
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.query_smarttag_template_list_with_options_async(query_smarttag_template_list_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:]) Update template
You can call the UpdateSmarttagTemplate operation to update template information. For more information about the fields and parameters of the operation, see UpdateSmarttagTemplate. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
# The template ID.
template_id='05de22f255284c7a8d2aab535dde****',
# The custom name of the template.
template_name='template-example-****',
# The industry of the file to be analyzed.
industry='common',
# The scenario.
scene='search',
# The analysis type.
analyse_types='ocr,asr',
# The IDs of the face libraries that are used for recognition.
face_category_ids='celebrity',
# The parameters of the face algorithm.
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# The IDs of the object libraries that are used for recognition.
object_group_ids='general,item,weapon,animal',
# The IDs of the landmark libraries that are used for recognition.
landmark_group_ids='common',
# Specifies whether the template is the default template.
is_default=True,
# The annotation type.
label_type='hmi',
# The version of smart tagging.
label_version='1.0',
# In smart tagging 2.0 and 2.0-custom modes,
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# The keyword tag configuration.
keyword_config='{ "type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.update_smarttag_template_with_options(update_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
# The template ID.
template_id='05de22f255284c7a8d2aab535dde****',
# The custom name of the template.
template_name='template-example-****',
# The industry of the file to be analyzed.
industry='common',
# The scenario.
scene='search',
# The analysis type.
analyse_types='ocr,asr',
# The IDs of the face libraries that are used for recognition.
face_category_ids='celebrity',
# The parameters of the face algorithm.
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# The IDs of the object libraries that are used for recognition.
object_group_ids='general,item,weapon,animal',
# The IDs of the landmark libraries that are used for recognition.
landmark_group_ids='common',
# Specifies whether the template is the default template.
is_default=True,
# The annotation type.
label_type='hmi',
# The version of smart tagging.
label_version='1.0',
# In smart tagging 2.0 and 2.0-custom modes,
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# The keyword tag configuration.
keyword_config='{ "type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.update_smarttag_template_with_options_async(update_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:]) Delete template
You can call the DeleteSmarttagTemplate operation to delete a template. For more information about the fields and parameters of the operation, see DeleteSmarttagTemplate. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
# The ID of the template that you want to delete.
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.delete_smarttag_template_with_options(delete_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
# The ID of the template that you want to delete.
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.delete_smarttag_template_with_options_async(delete_smarttag_template_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Register a custom face
You can call the RegisterCustomFace operation to register a custom face. For more information about the fields and parameters of the operation, see RegisterCustomFace. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The public URL of the face image to be registered.
image_url='http://example-****.jpeg'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.register_custom_face_with_options(register_custom_face_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The public URL of the face image to be registered.
image_url='http://example-****.jpeg'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.register_custom_face_with_options_async(register_custom_face_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Deregister a custom face
You can call the UnregisterCustomFace operation to unregister a custom face. For more information about the fields and parameters of the operation, see UnregisterCustomFace. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The face ID.
face_id='15****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.unregister_custom_face_with_options(unregister_custom_face_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The face ID.
face_id='15****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.unregister_custom_face_with_options_async(unregister_custom_face_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])Add a custom figure library or figure tag
You can call the TagCustomPerson operation to add a custom figure library or figure tag. For more information about the fields and parameters of the operation, see TagCustomPerson. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The name of the figure library.
category_name='CategoryNametest-****',
# The description of the figure library.
category_description='CategoryDescription001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The name of the figure.
person_name='PersonNametest-****',
# The description of the figure.
person_description='PersonDescriptiontest-****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.tag_custom_person_with_options(tag_custom_person_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
# The ID of the figure library.
category_id='CategoryId001-****',
# The name of the figure library.
category_name='CategoryNametest-****',
# The description of the figure library.
category_description='CategoryDescription001-****',
# The ID of the figure.
person_id='PersonId001-****',
# The name of the figure.
person_name='PersonNametest-****',
# The description of the figure.
person_description='PersonDescriptiontest-****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.tag_custom_person_with_options_async(tag_custom_person_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])List all figures and faces in a figure library
You can call the ListCustomPersons operation to list all figures and faces in a figure library. For more information about the fields and parameters of the operation, see ListCustomPersons. The following sample code is provided:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
Use an AccessKey pair to initialize the client.
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
# The ID of the figure library.
category_id='CategoryId-****',
# The ID of the figure.
person_id='PersonId-****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
client.list_custom_persons_with_options(list_custom_persons_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
# The ID of the figure library.
category_id='CategoryId-****',
# The ID of the figure.
person_id='PersonId-****'
)
runtime = util_models.RuntimeOptions()
try:
# If you copy the code, print the return value of the API operation.
await client.list_custom_persons_with_options_async(list_custom_persons_request, runtime)
except Exception as error:
# The system prints the error message. In a project, do not ignore exceptions.
# The error message.
print(error.message)
# The diagnostic address.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])