class Clarinet::Models

Attributes

raw_data[R]

@return [Hash] Raw API data used to construct this instance

Public Class Methods

new(app, raw_data = []) click to toggle source

@!visibility private

# File lib/clarinet/models.rb, line 30
def initialize(app, raw_data = [])
  @app = app
  @raw_data = raw_data

  @models = raw_data.map do |model_data|
    Clarinet::Model.new app, model_data
  end
end

Public Instance Methods

get(id) click to toggle source

Returns a model specified by ID @param id [String] The model's id @return [Clarinet::Model] Model instance

# File lib/clarinet/models.rb, line 86
def get(id)
  data = @app.client.model id
  Clarinet::Model.new @app, data[:model]
end
init_model(model) click to toggle source

Returns a Model instance given model id or name. It will call search if name is given. @param model [String, Hash, Clarinet::Model]

If String, it is assumed to be model id. Otherwise, if Hash is given, it can have any of the following keys:

@option model [String] :id Model id @option model [String] :name Model name @option model [String] :version Model version @option model [String] :type (nil) This can be “concept”, “color”, “embed”, “facedetect”, “cluster” or “blur” @return [Clarinet::Model] Model instance corresponding to the given id

or the first search result
# File lib/clarinet/models.rb, line 48
def init_model(model)
  model_data = {}

  model_data[:id] = model if model.is_a? String
  model_data = model if model.is_a? Hash
  model_data = model.raw_data if model.is_a? Clarinet::Model

  return Clarinet::Model.new @app, model_data if model_data[:id]

  search_results = search model_data[:name], model_data[:type]

  return search_results.find { |result| result.model_version.id == model_data[:version] }.first if model_data[:version]

  search_results.first
end
list(options = { page: 1, per_page: 20 }) click to toggle source

Return all the models @param options [Hash] Listing options @option options [Int] :page (1) The page number @option options [Int] :per_page (20) Number of models to return per page @return [Clarinet::Models]

# File lib/clarinet/models.rb, line 78
def list(options = { page: 1, per_page: 20 })
  data = @app.client.models options
  Clarinet::Models.new @app, data[:models]
end
predict(model, inputs) click to toggle source

Predict using a specific model @param model (see init_model) @param inputs (see Clarinet::Model#predict) @macro predict_inputs @return [Hash] Data returned by the API with symbolized keys

# File lib/clarinet/models.rb, line 69
def predict(model, inputs)
  init_model(model).predict(inputs)
end