调用百度api实现人工智能文本语义识别

 首先是新手去官网1 元买:

买完之后访问:

https://console.bce.baidu.com/ai/?fromai=1#/ai/nlp/app/list

 然后代码:

# encoding:utf-8
import requests
# 获取网址 https://console.bce.baidu.com/ai/?fromai=1#/ai/nlp/app/list
# Access Key	Hczb9XGhGcZ
# Secret Key    dGm5ERzvOt
# client_id 为官网获取的AK, client_secret 为官网获取的SK
# encoding:utf-8
import requests

# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Hczb9XGhGcZFaG79nGbosakj&client_secret=vOtFyAl8ts36h8KbbRLB20aGz'
response = requests.get(host)
if response:
    print(response.json())

def word_review(text):
    '''
    文本审核接口
    '''
    request_url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined"
    params = {"text":text}
    access_token = 5.282335-29293935'
    request_url = request_url + "?access_token=" + access_token
    headers = {'content-type': 'application/x-www-form-urlencoded'}
    response = requests.post(request_url, data=params, headers=headers)
    if response:
        res=response.json()['conclusion']
        return res
    else:
        r="系统错误请稍后再试"
        return r

你可能感兴趣的:(python实战100例,json,python,开发语言,人工智能)