12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/lita/handlers/onewheel_rekognition.rb', line 12
def handle_rekog(response)
input = response.matches[0][0]
Lita.logger.debug "Running rekog on '#{input}'"
uri = "#{config.lambda_uri}/upload?uri=#{input}"
Lita.logger.debug "uri: #{uri}"
upload_response = RestClient.post(uri, {})
data = JSON.parse(upload_response.body)
puts data.inspect
uri = "#{config.lambda_uri}/detect?bucket=#{data['bucket']}&filename=#{data['filename']}"
detect_response = RestClient.get(uri)
detected = JSON.parse(detect_response.body)
str = ''
detected['Labels'].each_with_index do |label, index|
str += ', ' if index > 0
str += "#{label['Name']} #{label['Confidence'].to_f.round(2)}%"
end
response.reply str
end
|