Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class AudioRecognition < Base
end
end

View File

@@ -0,0 +1,19 @@
module BrayniacAI
module AwsRequestSigning
def request(method, path, *arguments)
case method
when :patch, :put, :post
# These request types include a body and headers
body = arguments.first
headers = arguments.last
new_headers = AwsSignatureHeaders.new(method, self.site.merge(path), body, headers)
super(method, path, body, headers.merge(new_headers))
else
# All other request types only include headers
headers = arguments.first
new_headers = AwsSignatureHeaders.new(method, self.site.merge(path))
super(method, path, headers.merge(new_headers))
end
end
end
end

View File

@@ -0,0 +1,47 @@
module BrayniacAI
class AwsSignatureHeaders < Hash
def initialize(http_method, uri, body = "", headers = {})
@http_method = http_method
@uri = uri
@body = body
@headers = headers
set_headers
end
private
attr_reader :http_method, :uri, :body, :headers
def request_params
{
http_method: http_method,
url: uri,
body: body,
headers: headers,
}
end
def set_headers
# Set self to the signature headers
signature.headers.each { |key, value| self[key] = value }
end
def signature
signer.sign_request(request_params)
end
def signer
Aws::Sigv4::Signer.new(signer_params)
end
def signer_params
{
service: "execute-api", # TODO: can this be inferred from the URI?
region: ENV["AWS_REGION"],
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
}
end
end
end

View File

@@ -0,0 +1,5 @@
module BrayniacAI
class AwsSignedConnection < ActiveResource::Connection
prepend AwsRequestSigning
end
end

16
lib/brayniac_ai/base.rb Normal file
View File

@@ -0,0 +1,16 @@
module BrayniacAI
class Base < ActiveResource::Base
API_ENDPOINT = ENV.fetch("BRAYNIAC_AI_API_ENDPOINT")
self.connection_class = AwsSignedConnection
self.include_format_in_path = false
self.site = API_ENDPOINT
def self.enable_logging
ActiveSupport::Notifications.subscribe('request.active_resource') do |name, start, finish, id, payload|
puts payload
end
end
end
end

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class Collection < Base
end
end

View File

@@ -0,0 +1,11 @@
module BrayniacAI
class DocumentAnalysis < Base
def headshot_filename
object_name
end
def headshot_url
"https://s3.amazonaws.com/#{bucket_name}/#{headshot_filename}"
end
end
end

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class EdlParse < Base
end
end

View File

@@ -0,0 +1,5 @@
# TODO: Use this in EdlParse
module BrayniacAI
class EdlParseResult < Base
end
end

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class FacialRecognition < Base
end
end

View File

@@ -0,0 +1,5 @@
# TODO: Use this in FacialRecognition
module BrayniacAI
class FacialRecognitionResult < Base
end
end

44
lib/brayniac_ai/tag.rb Normal file
View File

@@ -0,0 +1,44 @@
module BrayniacAI
class Tag < Base
def to_a
[faces_list, labels_list, texts_list].concat.flatten
end
private
CATEGORIES = %w( AgeRange Gender )
BOOLEAN_CATEGORIES = %w( Beard Mustache Eyeglasses Sunglasses )
def faces_list
[].tap do |tags|
# Add the value of the category to the tags
tags.append convert_category_values_to_array CATEGORIES
# If the value for the category is true, add that category name to the tags
tags.append convert_category_booleans_to_array BOOLEAN_CATEGORIES
end
end
def labels_list
labels
end
def texts_list
text.map { |tag| tag.text }.uniq
end
def convert_category_values_to_array(categories)
categories.map do |category|
Array.wrap(faces.try(category)).map do |value|
value.titleize
end
end.flatten
end
def convert_category_booleans_to_array(categories)
categories.map do |category|
category if faces.try(category)
end.compact
end
end
end

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class Validation < Base
end
end