{"id":22203829,"url":"https://github.com/nicholalexander/clarification","last_synced_at":"2025-07-27T05:32:25.327Z","repository":{"id":62555704,"uuid":"103981576","full_name":"nicholalexander/clarification","owner":"nicholalexander","description":"Ruby Gem for Clarifai API v2","archived":false,"fork":false,"pushed_at":"2019-07-05T12:10:28.000Z","size":4050,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T03:21:08.377Z","etag":null,"topics":["ai","clarifai","machine-learning","ruby","ruby-wrapper"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/clarification","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicholalexander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-18T19:19:46.000Z","updated_at":"2020-12-08T10:12:59.000Z","dependencies_parsed_at":"2022-11-03T05:45:29.112Z","dependency_job_id":null,"html_url":"https://github.com/nicholalexander/clarification","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholalexander%2Fclarification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholalexander%2Fclarification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholalexander%2Fclarification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicholalexander%2Fclarification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicholalexander","download_url":"https://codeload.github.com/nicholalexander/clarification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227555721,"owners_count":17786213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","clarifai","machine-learning","ruby","ruby-wrapper"],"created_at":"2024-12-02T17:14:33.542Z","updated_at":"2024-12-02T17:14:34.480Z","avatar_url":"https://github.com/nicholalexander.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/clarification.svg)](https://badge.fury.io/rb/clarification)\n[![Build Status](https://travis-ci.org/nicholalexander/clarification.svg?branch=master)](https://travis-ci.org/nicholalexander/clarification)\n[![Test Coverage](https://codeclimate.com/github/nicholalexander/clarification/badges/coverage.svg)](https://codeclimate.com/github/nicholalexander/clarification/coverage)\n[![Code Climate](https://codeclimate.com/github/nicholalexander/clarification/badges/gpa.svg)](https://codeclimate.com/github/nicholalexander/clarification)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cb0dd6cce7ec48a191696780951c5efe)](https://www.codacy.com/app/nicholalexander/clarification?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=nicholalexander/clarification\u0026amp;utm_campaign=Badge_Grade)\n[![Inline docs](http://inch-ci.org/github/nicholalexander/clarification.svg?branch=master)](http://inch-ci.org/github/nicholalexander/clarification)\n\n# Clarification\n\nAn unofficial Ruby wrapper for the [Clarifai](http://clarifai.com) API.  This currently uses v2 of the API and was partially created because other Ruby gems are using v1 which is being depricated in late 2017.\n\nClarifai is an awesome service and hopefully this gem makes it easier to use it and to use AI image tagging in your Ruby apps.  Please let me know if there's something you'd like to see but don't or if you see something you wish you didn't.  Thanks!\n\nThis gem is currently in development and there is lots likely to change so please be aware!\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'clarification'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install clarification\n\n## Configuration\n\nConfigure the gem as you would normally configure a wonderful happy gem.\n\n```ruby\n  Clarification.configure do |config|\n    config.api_key = 'a_big_secret_you_got_from_clarifai'\n    config.default_public_models = [:food, :general]\n  end\n```\n\nThis should also work nicely inside a rails initializer.\n\n**Each endpoint initialized in your configuration will be called by default from the client.  So any predictions using a client configured with `:food` and `:general` will make two API requests.**\n\n**When [Workflow](https://clarifai.com/developer/guide/workflow#workflow) is implemented in the gem, you will be able to call against your workflow instead of the public models.**\n\nYou can also configure the client on the fly with  `client.set_active_models_by_public_key([:food, :general])`, `client.set_active_models_from_hash({food: 'fasldfsadflkjasdf'})` (useful for custom models) or `client.set_active_models(model)` where model is a Clarification::Model.  See more in Training.\n\n## Basic Usage\n\n```ruby\nclient = Clarification::Client.new\nresponse = client.predict.by_url(some_public_url_of_an_image)\n```\n\n### Prediction\n\nThe response object returned from the prediction is a hash containing a nicely parsed result for each of the models called.  In the above configuration example we have two models.  So we will have response[:food] and response[:general] after asking for a prediction.  Each of those model results have an object which has three pieces of relevant information: status, concepts, and response_json.\n\nThusly you can do things like this:\n\n```ruby\nresponse[:food].concepts.each do |concept|\n  if concept.value \u003e 0.90\n    puts \"#{concept.name}\"\n  end\nend\n```\n\n```ruby\nif response[:food].status.code == 10000\n  puts response[:food].status.description\nend\n```\n\nIf you want the actual api response, it's here:\n\n```ruby\nresponse[:general].response_json\n```\n\nAll the objects are OpenStructs currently, but I suspect this will change shortly.\n\nAs a convenience, the client also maintains the parsed response in the last_response variable.\n\n```ruby\nclient.predict.by_url(some_public_url_of_an_image)\nclient.predict.last_response #=\u003e {:food =\u003e Objectifier...}\n```\n\n### Search\n\nThe client has a search object which can be used to index images with the Clarifai application identified by the API key.  \n\nThusly you can do like this:\n\n```ruby\nimage_array = [ url_to_picture_of_kitten, url_to_picture_of_pizza, url_to_picture_of_drake]\nclient.search.index_images(image_array)\n```\n\nOnce you have your images indexed, you can go and search them by concepts that might be in your pictures as identified by Clarifai's general prediction model.\n\n```ruby\nresults = client.search.by_concept('cat')\nresults.hits.each do |hit|\n  puts hit.url if hit.score \u003e .90\nend\n```\n\nThe search client also saves the last search and searched concept as a matter of convenience.\n\n```ruby\nclient.search.last_search.hits.count\nclient.search.last_search.concept\n```\n\nGo and do likewise.\n\n### Train\n\nThere are three steps to setting up a custom model:\n\n* Add images with concepts.  \n* Create a model with the same concepts that you've associated with images.\n* Train said model.\n\nThese three steps can be accomplished thusly:\n\n```ruby\ncat_related_concepts = [\"cat\", \"feline\", \"superior\"]\nclient.train.add_image(some_url_of_a_cat, cat_related_concepts)\nmodel = client.train.create_model('cat', cat_related_concepts)\nclient.train.train_model(model)\n```\n\nNow that you have the model created and trained, you should be able to predict against it.  Though you may need to wait for Clarifai to finish the model training.\n\n```ruby\nclient.set_active_models([model])\nclient.predict.by_url(some_public_url)\n```\n\nWalla, as they say in France.\n\n## TODO's\n\nLots and lots of things.  Amongst them:\n\n* error handling\n* predict multiple images per call\n* predict video\n* better testing\n* documentation\n* use workflows\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nThe repo intentionally includes an api key in bin/console to make experimenting easy and quick.  If you plan on making a bunch of requests, you can easily sign up for [your own free key](https://clarifai.com/signup/).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/nicholalexander/clarification. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\nYou can also see various code reporting / CI info here:  \n[travis ci](https://travis-ci.org/nicholalexander/clarification)  \n[codacy](https://www.codacy.com/app/nicholalexander/clarification)  \n[code climate](https://codeclimate.com/github/nicholalexander/clarification)   \n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Clarification project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nicholalexander/clarification/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholalexander%2Fclarification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicholalexander%2Fclarification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicholalexander%2Fclarification/lists"}