Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. KEY = "7ccfba2675a34b65891ac6ffba1b5d9c"
  5. ENDPOINT = "https://aiproject3education.cognitiveservices.azure.com/face/v1.0/detect"
  6. image_url = "https://images.wisegeek.com/business-people-in-agreement.jpg"
  7. headers = {'Ocp-Apim-Subscription-Key': KEY}
  8.  
  9. params = {
  10. 'returnFaceId':'true',
  11. 'returnFaceLandmarks':'false',
  12. 'returnFaceAttributes':'emotion'
  13. }
  14.  
  15. response = requests.post(ENDPOINT, params=params, headers=headers,json={'url':image_url})
  16.  
  17. data = response.json()
  18.  
  19. nrp = len(data)
  20. nrs = 0
  21. for person in data:
  22. emotions = person['faceAttributes']['emotion']
  23. maxv = 0
  24. maxe = ""
  25. for emotion in emotions.keys():
  26. if emotions[emotion] > maxv:
  27. maxv = emotions[emotion]
  28. maxe = emotion
  29. if maxe == 'disgust' or maxe=='sadness' or maxe=='anger':
  30. nrs+=1
  31. elif maxe=='neutral':
  32. nrs+=0.5
  33. if nrp > 2:
  34. print("Bored") if nrs>=nrp//2 else print("Entertained")
  35. elif nrs>0:
  36. print("Bored")
  37. else:
  38. print("Entertained")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement