如何在 azure API 中发送文本作为输入并接收情绪或情感作为响应?
how to send text as an input and receive sentiment or emotion as a response in azure API?
-
azure-api-management
-
azure-api-apps
-
azure-app-service-envrmnt
-
azure-web-app-service
-
azure-cognitive-services
我想在 azure API 中实现一个 python 脚本。基本上,我想发送文本并接收情感或情绪。我假设 API 是写作方法还是网络应用程序?
您能否通过示例指导我查看文档?谢谢!
我认为这个Azure Text Analytics API could meet your requirement, this API provides you with Analyze sentiment functionality and associated python SDK. You can try the code below to get started with python SDK V2 sentiment函数:
from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
from msrest.authentication import CognitiveServicesCredentials
subscriptionKey = "<YOUR AZURE COGNITIVE SERVICE KEY>"
endpoint = "<YOUR AZURE COGNITIVE SERVICE SERVICE ENDPOINT>"
credentials = CognitiveServicesCredentials(subscriptionKey)
text_analytics = TextAnalyticsClient(endpoint=endpoint, credentials=credentials)
documents = [
{
"id": "1",
"language": "en",
"text": "I had the best day of my life."
}
]
response = text_analytics.sentiment(documents=documents)
for document in response.documents:
print("Document Id: ", document.id, ", Sentiment Score: ",
"{:.2f}".format(document.score))
结果:
您可以在 Azure 门户上找到您的服务终结点和订阅密钥:
在你 Create a Cognitive Service 在 Azure 门户上。
您可以将您的应用程序部署到Azure应用服务上,具体方法请参考this doc。
azure-api-management
azure-api-apps
azure-app-service-envrmnt
azure-web-app-service
azure-cognitive-services
我想在 azure API 中实现一个 python 脚本。基本上,我想发送文本并接收情感或情绪。我假设 API 是写作方法还是网络应用程序? 您能否通过示例指导我查看文档?谢谢!
我认为这个Azure Text Analytics API could meet your requirement, this API provides you with Analyze sentiment functionality and associated python SDK. You can try the code below to get started with python SDK V2 sentiment函数:
from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
from msrest.authentication import CognitiveServicesCredentials
subscriptionKey = "<YOUR AZURE COGNITIVE SERVICE KEY>"
endpoint = "<YOUR AZURE COGNITIVE SERVICE SERVICE ENDPOINT>"
credentials = CognitiveServicesCredentials(subscriptionKey)
text_analytics = TextAnalyticsClient(endpoint=endpoint, credentials=credentials)
documents = [
{
"id": "1",
"language": "en",
"text": "I had the best day of my life."
}
]
response = text_analytics.sentiment(documents=documents)
for document in response.documents:
print("Document Id: ", document.id, ", Sentiment Score: ",
"{:.2f}".format(document.score))
结果:
您可以在 Azure 门户上找到您的服务终结点和订阅密钥:
在你 Create a Cognitive Service 在 Azure 门户上。
您可以将您的应用程序部署到Azure应用服务上,具体方法请参考this doc。