def moderation_image(token, image, url, categories=None, threshold=None, moderation_rule="default"): endpoint = utils.get_endpoint(ais.AisService.MODERATION_SERVICE) _url = 'https://%s/v1.0/moderation/image' % endpoint if sys.version_info.major >= 3: if image: image = image.decode("utf-8") _data = { "image": image, "url": url, "categories": categories, "threshold": threshold, "moderation_rule": moderation_rule } status_code, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return resp else: return resp.decode('utf-8')
def image_content_batch(token, urls, categories=None, threshold=None): endpoint = utils.get_endpoint(ais.AisService.MODERATION_SERVICE) _url = 'https://%s/v1.0/moderation/image/batch' % endpoint _data = { "urls": urls, "categories": categories, "threshold": threshold, } if sys.version_info.major < 3: status_code, resp = utils.request_token(_url, _data, token, timeout=20) return resp else: utils.update_socket_time(timeout=20) status_code, resp = utils.request_token(_url, _data, token) return resp.decode('utf-8')
def _image_batch_jobs(endpoint, token, urls, categories=['politics', 'terrorism', 'p**n']): _url = 'https://%s/v1.0/moderation/image/batch/jobs' % endpoint _data = {"urls": urls, "categories": categories} status, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return status, resp else: return status, resp.decode('utf-8')
def distortion_correct(token, image, url, correction=True): endpoint = utils.get_endpoint(ais.AisService.MODERATION_SERVICE) _url = 'https://%s/v1.0/moderation/image/distortion-correct' % endpoint if sys.version_info.major >= 3: if image: image = image.decode("utf-8") _data = {"image": image, "url": url, "correction": correction} status_code, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return resp else: return resp.decode('utf-8')
def clarity_detect(token, image, url, threshold=0.8): endpoint = utils.get_endpoint(ais.AisService.MODERATION_SERVICE) _url = 'https://%s/v1.0/moderation/image/clarity-detect' % endpoint if sys.version_info.major >= 3: if image: image = image.decode("utf-8") _data = {"image": image, "url": url, "threshold": threshold} status_code, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return resp else: return resp.decode('utf-8')
def _moderation_video(endpoint, token, url, frame_interval=5, categories=['politics', 'terrorism']): _url = 'https://%s/v1.0/moderation/video' % endpoint _data = { "url": url, "frame_interval": frame_interval, "categories": categories } status, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return status, resp else: return status, resp.decode('utf-8')
def moderation_text( token, text, type='content', categories=["ad", "politics", "p**n", "abuse", "contraband", "flood"]): endpoint = utils.get_endpoint(ais.AisService.MODERATION_SERVICE) _url = 'https://%s/v1.0/moderation/text' % endpoint _data = { "categories": categories, # 检测场景 Array politics:涉政 p**n:涉黄 ad:广告 abuse:辱骂 contraband:违禁品 flood:灌水 "items": [{ "text": text, "type": type } # items: 待检测的文本列表 text 待检测文本 type 文本类型 ] } status_code, resp = utils.request_token(_url, _data, token) if sys.version_info.major < 3: return resp.decode('unicode-escape').encode('utf-8') else: return resp.decode('unicode_escape')