Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- KEY = "7ccfba2675a34b65891ac6ffba1b5d9c"
- ENDPOINT = "https://aiproject3education.cognitiveservices.azure.com/face/v1.0/detect"
- image_url = "https://images.wisegeek.com/business-people-in-agreement.jpg"
- headers = {'Ocp-Apim-Subscription-Key': KEY}
- params = {
- 'returnFaceId':'true',
- 'returnFaceLandmarks':'false',
- 'returnFaceAttributes':'emotion'
- }
- response = requests.post(ENDPOINT, params=params, headers=headers,json={'url':image_url})
- data = response.json()
- nrp = len(data)
- nrs = 0
- for person in data:
- emotions = person['faceAttributes']['emotion']
- maxv = 0
- maxe = ""
- for emotion in emotions.keys():
- if emotions[emotion] > maxv:
- maxv = emotions[emotion]
- maxe = emotion
- if maxe == 'disgust' or maxe=='sadness' or maxe=='anger':
- nrs+=1
- elif maxe=='neutral':
- nrs+=0.5
- if nrp > 2:
- print("Bored") if nrs>=nrp//2 else print("Entertained")
- elif nrs>0:
- print("Bored")
- else:
- print("Entertained")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement