我是在python中使用文本审核功能,下午时都能正常使用,但到了晚上时就出现了错误:
'AipImageCensor' object has no attribute 'textCensorUserDefined'
关键是下午可正常使用,这让我这个新手就比较头晕了,我的python代码如下:
# coding=gbk
from aip import AipContentCensor
class ContentCensorText():
"""
百度AI-内容审核(文本)
"""
def __init__(self,params):
APP_ID = params["APP_ID"]
API_KEY = params["API_KEY"]
SECRET_KEY = params["SECRET_KEY"]
self.defineText = params["defineText"]
self.client = AipContentCensor(APP_ID, API_KEY, SECRET_KEY)
self.msg = {}
self.run()
def run(self):
try:
words = []
result = self.client.textCensorUserDefined(self.defineText)
conclusion = result["conclusion"]
if conclusion == "合规":
self.msg = {
"结果":"合规"
}
else:
for row_data in result["data"]:
words += [word for row_hits in row_data["hits"] for word in row_hits["words"]]
self.msg = {
"结果":"不合规",
"words":",".join(words),
}
except Exception as e:
self.msg = {
"结果":str(e)
}
def __str__(self):
return str(self.msg)
if __name__ == '__main__':
params = {
'APP_ID':'xxxxx',
'API_KEY':'xxxx',
'SECRET_KEY':'xxxxx',
'defineText':"曾命名为“今日TT媒体平台”,是今日TT旗下媒体/自媒体平台,致力于帮助企业、机构、媒体和自媒体在移动端获得更多曝光和关注,在移动互联网时代持续扩大影响力,同时实现品牌传播和内容变现。另一方面也为今日TT这个用户量众多的平台输出更优",
}
obj = ContentCensorText(params)
print(obj.msg)
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
我的 client.textCensorUserDefined 直接是undefined 了,哭泣
可添加下相关的qq群问下技术支持人员,文本审核:983259607