baidu.py 851 B

123456789101112131415161718192021222324252627
  1. # encoding:utf-8
  2. import requests
  3. def assess_token():
  4. # client_id 为官网获取的AK, client_secret 为官网获取的SK
  5. host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=orZUHE5R2gTiPzzY1X4cRaqi&client_secret=48ObBtvIoYNWdFQ8RTZGR6DsQq9VLBpb'
  6. response = requests.get(host)
  7. if response:
  8. return response.json()
  9. def similarity(assess_token):
  10. url = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/simnet?charset=UTF-8&access_token=' + assess_token
  11. body = {
  12. "text_1": "张斌仁",
  13. "text_2": "张斌",
  14. "model": "CNN"
  15. }
  16. response = requests.post(url, json=body)
  17. if response:
  18. print(response.json())
  19. if __name__ == '__main__':
  20. # print(assess_token())
  21. similarity('24.2b77398439546b3a983e9b93b84dbe14.2592000.1610182288.282335-23131081')