Reputation: 39
I would like to implement a python script in an azure API. Basically, I would like to send text and receive emotion or sentiment. I am assuming that the API is the writing approach or is it a web app? Would you be able to direct me to documentation with an example? Thank you!
Upvotes: 0
Views: 141
Reputation: 12153
I think this 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 function:
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))
You can find your service endpoint and subscriptionKey on Azure portal:
After you Create a Cognitive Service on Azure portal.
You can deploy your application on the Azure app service, for how to do it, just refer to this doc.
Upvotes: 1