huaweicloud-sdk-python-v3/huaweicloud-sdk-moderation/huaweicloudsdkmoderation/v1/moderation_client.py

457 lines
16 KiB
Python
Raw Normal View History

2020-05-18 07:34:40 +00:00
# coding: utf-8
from __future__ import absolute_import
import datetime
import re
import importlib
import six
from huaweicloudsdkcore.client import Client, ClientBuilder
2020-05-18 07:34:40 +00:00
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.utils import http_utils
from huaweicloudsdkcore.sdk_stream_request import SdkStreamRequest
2020-05-18 07:34:40 +00:00
class ModerationClient(Client):
"""
:param configuration: .Configuration object for this client
:param pool_threads: The number of threads to use for async requests
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
NATIVE_TYPES_MAPPING = {
'int': int,
'long': int if six.PY3 else long,
'float': float,
'str': str,
'bool': bool,
'date': datetime.date,
'datetime': datetime.datetime,
'object': object,
}
def __init__(self):
super(ModerationClient, self).__init__()
self.model_package = importlib.import_module("huaweicloudsdkmoderation.v1.model")
self.preset_headers = {'User-Agent': 'HuaweiCloud-SDK-Python'}
@staticmethod
def new_builder(clazz):
return ClientBuilder(clazz)
2020-05-18 07:34:40 +00:00
def run_image_batch_moderation(self, request):
"""图像内容检测(批量)
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户
:param RunImageBatchModerationRequest request
:return: RunImageBatchModerationResponse
"""
return self.run_image_batch_moderation_with_http_info(request)
def run_image_batch_moderation_with_http_info(self, request):
"""图像内容检测(批量)
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户
:param RunImageBatchModerationRequest request
:return: RunImageBatchModerationResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['body']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
2020-05-18 07:34:40 +00:00
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/image/batch',
method='POST',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunImageBatchModerationResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
2020-05-18 07:34:40 +00:00
def run_image_moderation(self, request):
"""图像内容检测
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户
:param RunImageModerationRequest request
:return: RunImageModerationResponse
"""
return self.run_image_moderation_with_http_info(request)
def run_image_moderation_with_http_info(self, request):
"""图像内容检测
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户
:param RunImageModerationRequest request
:return: RunImageModerationResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['image_detection_req']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
2020-05-18 07:34:40 +00:00
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/image',
method='POST',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunImageModerationResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
2020-05-18 07:34:40 +00:00
def run_text_moderation(self, request):
"""文本内容检测
分析并识别用户上传的文本内容是否有敏感内容如色情政治等并将识别结果返回给用户
:param RunTextModerationRequest request
:return: RunTextModerationResponse
"""
return self.run_text_moderation_with_http_info(request)
def run_text_moderation_with_http_info(self, request):
"""文本内容检测
分析并识别用户上传的文本内容是否有敏感内容如色情政治等并将识别结果返回给用户
:param RunTextModerationRequest request
:return: RunTextModerationResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['text_detection_req']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
2020-05-18 07:34:40 +00:00
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/text',
method='POST',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunTextModerationResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
def run_check_result(self, request):
"""图像内容检测(异步批量)- 处理结果查询
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户 > 说明 任务最长保留时间为30分钟过期后会被清理掉建议在任务提交后每30s进行一次周期查询
:param RunCheckResultRequest request
:return: RunCheckResultResponse
"""
return self.run_check_result_with_http_info(request)
def run_check_result_with_http_info(self, request):
"""图像内容检测(异步批量)- 处理结果查询
分析并识别用户上传的图像内容是否有敏感内容如涉及政治人物暴恐元素涉黄内容等并将识别结果返回给用户 > 说明 任务最长保留时间为30分钟过期后会被清理掉建议在任务提交后每30s进行一次周期查询
:param RunCheckResultRequest request
:return: RunCheckResultResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['job_id']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
if 'job_id' in local_var_params:
query_params.append(('job_id', local_var_params['job_id']))
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/image/batch',
method='GET',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunCheckResultResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
2020-05-18 07:34:40 +00:00
def run_check_task_jobs(self, request):
"""图像内容检测(批量)- 任务列表查询
查询批量图像内容检测任务列表可通过指定任务状态查询来对任务列表进行过滤
:param RunCheckTaskJobsRequest request
:return: RunCheckTaskJobsResponse
"""
return self.run_check_task_jobs_with_http_info(request)
def run_check_task_jobs_with_http_info(self, request):
"""图像内容检测(批量)- 任务列表查询
查询批量图像内容检测任务列表可通过指定任务状态查询来对任务列表进行过滤
:param RunCheckTaskJobsRequest request
:return: RunCheckTaskJobsResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['status']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
if 'status' in local_var_params:
query_params.append(('status', local_var_params['status']))
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/image/batch/jobs',
method='GET',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunCheckTaskJobsResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
2020-05-18 07:34:40 +00:00
def run_task_sumbit(self, request):
"""图像内容检测(批量)- 任务提交
提交批量图像内容检测任务返回任务标识任务标识可用于查询任务结果此接口为异步接口相对于批量接口支持更大图片列表批次
:param RunTaskSumbitRequest request
:return: RunTaskSumbitResponse
"""
return self.run_task_sumbit_with_http_info(request)
def run_task_sumbit_with_http_info(self, request):
"""图像内容检测(批量)- 任务提交
提交批量图像内容检测任务返回任务标识任务标识可用于查询任务结果此接口为异步接口相对于批量接口支持更大图片列表批次
:param RunTaskSumbitRequest request
:return: RunTaskSumbitResponse
2020-05-18 07:34:40 +00:00
"""
all_params = ['body']
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = {}
2020-05-18 07:34:40 +00:00
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
if isinstance(request, SdkStreamRequest):
body_params = request.get_file_stream()
2020-05-18 07:34:40 +00:00
response_headers = []
2020-05-18 07:34:40 +00:00
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
2020-05-18 07:34:40 +00:00
auth_settings = []
return self.call_api(
resource_path='/v1.0/moderation/image/batch/jobs',
method='POST',
path_params=path_params,
query_params=query_params,
header_params=header_params,
2020-05-18 07:34:40 +00:00
body=body_params,
post_params=form_params,
response_type='RunTaskSumbitResponse',
response_headers=response_headers,
2020-05-18 07:34:40 +00:00
auth_settings=auth_settings,
collection_formats=collection_formats,
request_type=request.__class__.__name__)
2020-05-18 07:34:40 +00:00
def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None,
post_params=None, response_type=None, response_headers=None, auth_settings=None,
collection_formats=None, request_type=None):
2020-05-18 07:34:40 +00:00
"""Makes the HTTP request and returns deserialized data.
:param resource_path: Path to method endpoint.
:param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Query parameters in the url.
:param header_params: Header parameters to be placed in the request header.
2020-05-18 07:34:40 +00:00
:param body: Request body.
:param post_params dict: Request post form parameters,
for `application/x-www-form-urlencoded`, `multipart/form-data`.
:param auth_settings list: Auth Settings names for the request.
:param response_type: Response data type.
:param response_headers: Header should be added to response data.
2020-05-18 07:34:40 +00:00
:param collection_formats: dict of collection formats for path, query,
header, and post parameters.
:param request_type: Request data type.
2020-05-18 07:34:40 +00:00
:return:
Return the response directly.
"""
return self.do_http_request(
method=method,
resource_path=resource_path,
path_params=path_params,
query_params=query_params,
header_params=header_params,
body=body,
post_params=post_params,
response_type=response_type,
response_headers=response_headers,
collection_formats=collection_formats,
request_type=request_type)