在Python中使用Microsoft情感API获取图像的情感?
如果我们使用Python创建图像的情感,如快乐,悲伤,中性,惊喜等,那么每个人都会有喜怒哀乐,悲伤,中性,惊喜,悲伤等情感。我们可以将Microsoft情感API用于任何开发目的。
我们可以使用Microsoft情感API轻松阐述所有这些情感。
范例程式码
import http.client, urllib.request
import urllib.parse, urllib.error
import base64, sys
import simplejson as json
# replace with subscription_key
# you obtained after registration
subscription_key = '23d39244dbe55173214b56ab45d56cla'
headers = {
# Request for headers. And also replace the placeholder key with
# our subscription key.
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscription_key,
}
params = urllib.parse.urlencode({
})
url1 = 'IMAGE OF URL '
body = { 'url': url1 }
newbody =str(body)
try:
conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", "/emotion/v1.0/recognize?%s" % params, newbody, headers)
response = conn.getresponse()
data = response.read()
my_parsed = json.loads(data)
print ("响应是:")
print (json.dumps(my_parsed, sort_keys=True, indent=2))
val = my_parsed[0]["scores"]
res = max(val, key = val.get)
print ("\nEmotionoutput :: ",res)
conn.close()
except Exception as e:
print(e.args)热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短