Last active
May 7, 2016 13:52
-
-
Save devStepsize/a215918ceda27dbe9b025fd6d85565b1 to your computer and use it in GitHub Desktop.
Analyse the tone / emotion of a text with this beta IBM Watson service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
creds = { | |
"url": "https://gateway.watsonplatform.net/tone-analyzer-beta/api", | |
"password": "your_password", | |
"username": "your_username" | |
} | |
def get_tone(text): | |
endpoint = "https://gateway.watsonplatform.net/tone-analyzer-beta/api/v3/tone" | |
params = { | |
"version": "2016-02-11" | |
} | |
text = {"text": text} | |
headers = {'content-type': 'application/json'} | |
resp = requests.post(endpoint, json=text, auth=(creds['username'], creds['password']), params=params, headers=headers) | |
r = resp.json() | |
return [(e['tone_name'], e['score']) for e in r['document_tone']['tone_categories'][0]['tones']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment