1 Star 0 Fork 1

SmileToLin/api - 童趣识物prd文档

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
百度API调用.py 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
Yelena 提交于 2021-01-23 12:34 . 上传文件
#!/usr/bin/env python
# coding: utf-8
# In[22]:
# 百度API_
# 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=sF3jyK0oLkzhXkvi12XFwarl&client_secret=xF2dE9IWYID9Z7zx6QKCW9O9BLN8PXyG'
response = requests.get(host)
if response:
print(response.json())
# In[26]:
# encoding:utf-8
import requests
import base64
'''
动物识别
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/animal"
# 二进制方式打开图片文件
f = open(r'C:\Users\jane\OneDrive\桌面\大二\rabbit.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = '24.ee2667bcbeda0d798b828d512b18b553.2592000.1613896418.282335-23576914'
request_url = request_url + "?access_token=" + access_token
headers = {
'Content-Type': 'application/json',
}
response = requests.post(request_url, data=params, headers=headers)
if response:
print (response.json())
# In[27]:
# encoding:utf-8
import requests
import base64
'''
植物识别
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant"
# 二进制方式打开图片文件
f = open(r'C:\Users\jane\OneDrive\桌面\flower.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = '24.ee2667bcbeda0d798b828d512b18b553.2592000.1613896418.282335-23576914'
request_url = request_url + "?access_token=" + access_token
headers = {
'Content-Type': 'application/json',
}
response = requests.post(request_url, data=params, headers=headers)
if response:
print (response.json())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SmileToLin/api-prd.git
git@gitee.com:SmileToLin/api-prd.git
SmileToLin
api-prd
api - 童趣识物prd文档
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385