from aip import AipNlp
from openpyxl import load_workbook

# 填写你的自然语言处理应用的App ID、API Key、Secret Key
APP_ID = ''
API_Key = ''
Secret_Key = ''
client = AipNlp(APP_ID, API_Key, Secret_Key)
# 读取第一条商品评价（D4单元格）
wb = load_workbook('./data/商品评价.xlsx')
ws = wb.active
comment = ws.cell(row=2, column=4).value
# 调用百度AI情感倾向分析接口
result = client.sentimentClassify(comment)
# 格式化输出接口的返回值
positive = result['items'][0]['positive_prob']
negative = result['items'][0]['negative_prob']
confidence = result['items'][0]['confidence']
print('---笔记本电脑评价的情感倾向分析---')
print('情感属于积极类别的概率:', round(positive * 100, 4), '%')
print('情感属于消极类别的概率:', round(negative * 100, 4), '%')
print('分类的置信度:', round(confidence * 100, 4), '%')
