python 调用百度sdk

Boblee人工智能硕士毕业,擅长及爱好python,基于python研究人工智能、群体智能、区块链等技术,并使用python开发先后端、爬虫等。html

1.百度
python

      百度云提供丰富的人工智能接口供人们进行调用。https://cloud.baidu.comnginx

      注册并登录百度云后选择sdk,本文以图像审核为例进行使用。
web

  点击建立应用,填入使用名称及目的。后端

    点击查看应用详情。保存appid、appkey、secretkey。
微信

2.python调用
数据结构

     python安装app

pip install baidu-aip

     填入appid、appkey、secretkey,根据请求的不一样传入不一样参数,对应文档。https://cloud.baidu.com/doc/ANTIPORN/index.html。区块链

   请求参数。
人工智能

返回数据结构。

代码:

import osfrom config import Configfrom aip import AipImageCensordef get_file_content(file_path): with open(file_path, 'rb') as fp:        return fp.read()def baidu_supervision(file_path): """ 调用图像审核接口 """ """ 一、ocr:通用文字识别 二、public:公众人物识别 三、politician:政治人物识别 四、antiporn:色情识别  五、terror:暴恐识别。 六、webimage:网图OCR识别 七、disgust:恶心图 八、watermark:水印、二维码 """ try: client = AipImageCensor(Config.APP_ID, Config.API_KEY, Config.SECRET_KEY) result = client.imageCensorComb( get_file_content(file_path), [ 'terror', 'antiporn', ] ) antiporn = result['result']['antiporn']['conclusion'] terror = result['result']['terror']['result_coarse'][0]['name'] if antiporn == '正常' and terror == '正常': status = '正常' else: status = '有问题' return {'status': status} except: return {'status': '百度出问题'}


本文分享自微信公众号 - python制霸(pythonzhiba)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索