-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path测颜值.py
35 lines (28 loc) · 995 Bytes
/
测颜值.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
import base64
host = 'https://aip.baidubce.com/oauth/2.0/token?'
tokendata={
'grant_type': 'client_credentials',
'client_id': 'jCmFKlft9TwO4wGRhC8fye98',
'client_secret': 'mavTcDRK1UMCMwmm0EmQeNc9EGEdFGfp'
}
# 获取AccessToken
# host = host + urlencode(tokendata)
access_token = requests.post(host, data=tokendata).json()['access_token']
# 对图片颜值 beauty进行获取
url = 'https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token={}'.format(access_token)
headers = {
'Content - Type': 'application/json'
}
# 构造请求参数
data = {
'image': '',
'image_type': 'BASE64',
'face_field': 'beauty'
}
with open('颜值排行/一半.jpg', 'rb') as f:
data['image'] = base64.b64encode(f.read())
response = requests.post(url, headers=headers, data=data)
beauty = response.json()['result']['face_list'][0]['beauty']
# beauty = response.json()
print('韩', beauty)