Back to Parent

#------------------------------------------------------------------------------

#                           gems for both APIs:

#                      Microsoft Azure & theMovieDB

#------------------------------------------------------------------------------

require 'net/http'   #emotion API library

require 'parseconfig'
require 'rest-client'
require 'themoviedb-api'  #moviedb database




#------------------------------------------------------------------------------

#                         call for the movieDb API

#------------------------------------------------------------------------------


Tmdb::Api.key("aa73605e3dfbc5266697038b580c3678")

#call

response = Tmdb::Genre.movies(12)
response2 = Tmdb::Genre.movies(10749)



#------------------------------------------------------------------------------

#                         call for the Azure face API

#------------------------------------------------------------------------------

  uri = URI('https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect')
  uri.query = URI.encode_www_form({
      # Request parameters

      'returnFaceId' => 'true',
      'returnFaceLandmarks' => 'false',
      'returnFaceAttributes' => 'age,gender,headPose,smile,facialHair,glasses,' +
          'emotion,hair,makeup,occlusion,accessories,blur,exposure,noise'
  })

  request = Net::HTTP::Post.new(uri.request_uri)

  # Request headers

  # Replace <Subscription Key> with your valid subscription key.

  request['Ocp-Apim-Subscription-Key'] = '74e4615ad75b40179c0cca590c66615c'
  request['Content-Type'] = 'application/json'

  imageUri = media_url
  request.body = "{\"url\": \"" + imageUri + "\"}"

  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
      http.request(request)
  end

#call

json = JSON.parse( response.body )

emotions = json.first["faceAttributes"]["emotion"]

searchEmotion = emotions.max_by{|k,v| v}[0]
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0