
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Get emotions of images using Microsoft emotion API in Python?
Every human being have emotions just like happy, sad, neutral, surprise, sorrow etc., if we create the emotions of images like happy, sad, neutral, surprise, etc. in Python. We can use Microsoft emotion API for any development purpose.
We can easily elaborate all these emotions using Microsoft emotion API's.
Example Code
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 ("Response is:") 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)
- Related Articles
- Using the Microsoft Graph API
- How to create Microsoft Word paragraphs and insert Images in Python?
- Python Grayscaling of Images using OpenCV
- Reading images using Python?
- Get a google map image of specified location using Google Static Maps API in Python
- Theories of Emotion
- Erosion and Dilation of images using OpenCV in Python
- Addition and Blending of images using OpenCv in Python
- How to get year in android using year API class?
- Types of Emotions
- Speech Recognition in Python using Google Speech API
- Fetching top news using news API in Python
- Arithmetic Operations on Images using OpenCV in Python
- How to get local time in android using localtime API class?
- How to get month information in android using yearmonth API class?

Advertisements