clarification 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +23 -5
- data/bin/console +6 -1
- data/clarification.gemspec +2 -1
- data/lib/clarification.rb +2 -0
- data/lib/clarification/client.rb +2 -1
- data/lib/clarification/requester.rb +1 -3
- data/lib/clarification/requester/train_requester.rb +82 -0
- data/lib/clarification/train.rb +27 -0
- data/lib/clarification/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196adfa8582e30a4ec2e5ac0ef5afeceb7a0c5ce
|
4
|
+
data.tar.gz: 7b2d38f850dc20a8694bf03af3888b110fa5a82c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35a9592a72c30a67ccf53e68903ce8c58aab6eaf2a634d3517baac2d105a6636fb19a7e887e5515b522137cfbe693e9d2350c906e06c87b637f477cff4a1e0b4
|
7
|
+
data.tar.gz: '073775787600d87b2864b0c70a1a5cc7ce4b729aa39984faf453eb5a79f45f02ac12987aa187e1f308f646d1072bb1727b3251d7d19a810d512d493bea24a15c'
|
data/.travis.yml
CHANGED
@@ -5,3 +5,14 @@ rvm:
|
|
5
5
|
- 2.3
|
6
6
|
- 2.2
|
7
7
|
before_install: gem install bundler -v 1.15.4
|
8
|
+
env:
|
9
|
+
global:
|
10
|
+
- CC_TEST_REPORTER_ID=4baf3d26837a411d55ee4f861c8d49265755a03f4a0bb35fba9290cedae3f233
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at nichol.alexander@gmail.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/clarification.svg)](https://badge.fury.io/rb/clarification)
|
2
2
|
[![Build Status](https://travis-ci.org/nicholalexander/clarification.svg?branch=master)](https://travis-ci.org/nicholalexander/clarification)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/nicholalexander/clarification/badges/coverage.svg)](https://codeclimate.com/github/nicholalexander/clarification/coverage)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/nicholalexander/clarification/badges/gpa.svg)](https://codeclimate.com/github/nicholalexander/clarification)
|
3
5
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cb0dd6cce7ec48a191696780951c5efe)](https://www.codacy.com/app/nicholalexander/clarification?utm_source=github.com&utm_medium=referral&utm_content=nicholalexander/clarification&utm_campaign=Badge_Grade)
|
4
6
|
|
5
7
|
# Clarification
|
@@ -96,7 +98,7 @@ image_array = [ url_to_picture_of_kitten, url_to_picture_of_pizza, url_to_pictur
|
|
96
98
|
client.search.index_images(image_array)
|
97
99
|
```
|
98
100
|
|
99
|
-
Once you have your images indexed, you can go and search them by concepts that might be in your
|
101
|
+
Once 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.
|
100
102
|
|
101
103
|
```ruby
|
102
104
|
results = client.search.by_concept('cat')
|
@@ -116,6 +118,23 @@ Go and do likewise.
|
|
116
118
|
|
117
119
|
### Train
|
118
120
|
|
121
|
+
There are three steps to setting up a custom model:
|
122
|
+
|
123
|
+
* Add images with concepts.
|
124
|
+
* Create a model with the same concepts that you've associated with images.
|
125
|
+
* Train said model.
|
126
|
+
|
127
|
+
These three steps can be accomplished thusly:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
cat_related_concepts = ["cat", "feline", "superior"]
|
131
|
+
client.train.add_image(some_url_of_a_cat, cat_related_concepts)
|
132
|
+
client.train.create_model('cat', cat_related_concepts)
|
133
|
+
client.train.train_model('cat')
|
134
|
+
```
|
135
|
+
|
136
|
+
Now that you have the model created and trained, you should be able to predict against it. Except right now, that's not implemented in the Gem... womp womp.
|
137
|
+
|
119
138
|
## TODO's
|
120
139
|
|
121
140
|
Lots and lots of things. Amongst them:
|
@@ -124,11 +143,10 @@ Lots and lots of things. Amongst them:
|
|
124
143
|
* error handling
|
125
144
|
* predict multiple images per call
|
126
145
|
* predict video
|
127
|
-
* better testing
|
146
|
+
* better testing
|
128
147
|
* documentation
|
129
148
|
* use workflows
|
130
|
-
*
|
131
|
-
* training custom models
|
149
|
+
* predict against
|
132
150
|
|
133
151
|
## Development
|
134
152
|
|
@@ -140,7 +158,7 @@ The repo intentionally includes an api key in bin/console to make experimenting
|
|
140
158
|
|
141
159
|
Bug 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.
|
142
160
|
|
143
|
-
You can also see various code reporting / CI info here:
|
161
|
+
You can also see various code reporting / CI info here:
|
144
162
|
[travis ci](https://travis-ci.org/nicholalexander/clarification)
|
145
163
|
[codacy](https://www.codacy.com/app/nicholalexander/clarification)
|
146
164
|
[code climate](https://codeclimate.com/github/nicholalexander/clarification)
|
data/bin/console
CHANGED
@@ -12,7 +12,7 @@ Clarification.configure do |config|
|
|
12
12
|
config.default_public_models = [:food, :general]
|
13
13
|
end
|
14
14
|
|
15
|
-
@images = YAML.load_file("spec/
|
15
|
+
@images = YAML.load_file("spec/fixtures/images.yml")
|
16
16
|
|
17
17
|
@urls = [ @images[:mountains], @images[:kitten], @images[:drake] ]
|
18
18
|
|
@@ -40,6 +40,11 @@ end
|
|
40
40
|
# @client.search.by_concepts
|
41
41
|
# @client.search.by_images
|
42
42
|
|
43
|
+
@url = @images[:faces]
|
44
|
+
@concepts = ["faces", "people", "humans"]
|
45
|
+
@client.train.add_image(@url, @concepts)
|
46
|
+
@client.train.create_model('faces', @concepts)
|
47
|
+
@client.train.train_model('faces')
|
43
48
|
|
44
49
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
45
50
|
require "pry"
|
data/clarification.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "guard"
|
33
33
|
spec.add_development_dependency "guard-rspec"
|
34
34
|
spec.add_development_dependency "simplecov"
|
35
|
-
spec.add_development_dependency "
|
35
|
+
spec.add_development_dependency "webmock"
|
36
|
+
spec.add_development_dependency "vcr"
|
36
37
|
|
37
38
|
end
|
data/lib/clarification.rb
CHANGED
@@ -9,7 +9,9 @@ require "clarification/response"
|
|
9
9
|
require "clarification/response/search_response"
|
10
10
|
require "clarification/requester"
|
11
11
|
require "clarification/requester/search_requester"
|
12
|
+
require "clarification/requester/train_requester"
|
12
13
|
require "clarification/search"
|
14
|
+
require "clarification/train"
|
13
15
|
require "clarification/version"
|
14
16
|
|
15
17
|
require 'net/http'
|
data/lib/clarification/client.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Clarification
|
2
2
|
class Client
|
3
3
|
|
4
|
-
attr_reader :active_public_models, :last_response, :search
|
4
|
+
attr_reader :active_public_models, :last_response, :search, :train
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
raise "No Configuration Found." if Clarification.configuration.nil?
|
8
8
|
@active_public_models = Clarification.configuration.default_public_models
|
9
9
|
@last_response = nil
|
10
10
|
@search = Search.new
|
11
|
+
@train = Train.new
|
11
12
|
end
|
12
13
|
|
13
14
|
def predict(url)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Clarification
|
2
2
|
class Requester
|
3
3
|
|
4
|
-
def initialize(model_array)
|
4
|
+
def initialize(model_array=[])
|
5
5
|
@model_array = model_array
|
6
6
|
end
|
7
7
|
|
@@ -28,8 +28,6 @@ module Clarification
|
|
28
28
|
return response
|
29
29
|
end
|
30
30
|
|
31
|
-
private
|
32
|
-
|
33
31
|
def body_builder(url)
|
34
32
|
{
|
35
33
|
"inputs": [
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Clarification
|
2
|
+
class TrainRequester < Clarification::Requester
|
3
|
+
|
4
|
+
def add_image_with_concepts(target_url, concept_array)
|
5
|
+
uri = uri_builder("inputs")
|
6
|
+
body = image_with_concepts_body_builder(target_url, concept_array)
|
7
|
+
response = get_response(uri, body)
|
8
|
+
return response
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_model(name, concept_array)
|
12
|
+
uri = uri_builder("models")
|
13
|
+
body = create_model_body_builder(name, concept_array)
|
14
|
+
response = get_response(uri, body)
|
15
|
+
return response
|
16
|
+
end
|
17
|
+
|
18
|
+
def train_model(id)
|
19
|
+
uri = uri_builder("models/#{id}/versions")
|
20
|
+
body = {}
|
21
|
+
response = get_response(uri, body)
|
22
|
+
return response
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def uri_builder(path)
|
28
|
+
url = "#{Clarification::BASE_URL}#{path}"
|
29
|
+
URI.parse(url)
|
30
|
+
end
|
31
|
+
|
32
|
+
def image_with_concepts_body_builder(target_url, concept_array)
|
33
|
+
body_concepts = []
|
34
|
+
|
35
|
+
concept_array.each do |concept|
|
36
|
+
body_concepts << {
|
37
|
+
id: concept,
|
38
|
+
value: true
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
{
|
43
|
+
inputs: [
|
44
|
+
{
|
45
|
+
data: {
|
46
|
+
image: {
|
47
|
+
url: target_url
|
48
|
+
},
|
49
|
+
concepts: body_concepts
|
50
|
+
}
|
51
|
+
}
|
52
|
+
]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_model_body_builder(name, concept_array)
|
57
|
+
body_concepts = []
|
58
|
+
|
59
|
+
concept_array.each do |concept|
|
60
|
+
body_concepts << {
|
61
|
+
id: concept,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
{
|
66
|
+
model: {
|
67
|
+
id: name,
|
68
|
+
output_info: {
|
69
|
+
data: {
|
70
|
+
concepts: body_concepts
|
71
|
+
},
|
72
|
+
output_config: {
|
73
|
+
concepts_mutually_exclusive: false,
|
74
|
+
closed_environment:false
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Clarification
|
2
|
+
class Train
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@model_id = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_image(image, concept_array)
|
9
|
+
training_requester = TrainRequester.new
|
10
|
+
response = training_requester.add_image_with_concepts(image, concept_array)
|
11
|
+
return response # will be mostly status
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_model(name, concept_array)
|
15
|
+
training_requester = TrainRequester.new
|
16
|
+
response = training_requester.create_model(name, concept_array)
|
17
|
+
return response # should contain id and set model id?
|
18
|
+
end
|
19
|
+
|
20
|
+
def train_model(id)
|
21
|
+
training_requester = TrainRequester.new
|
22
|
+
response = training_requester.train_model(id)
|
23
|
+
return response # should be status.
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clarification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nichol Alexander
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -123,7 +123,21 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
@@ -165,9 +179,11 @@ files:
|
|
165
179
|
- lib/clarification/objectifier.rb
|
166
180
|
- lib/clarification/requester.rb
|
167
181
|
- lib/clarification/requester/search_requester.rb
|
182
|
+
- lib/clarification/requester/train_requester.rb
|
168
183
|
- lib/clarification/response.rb
|
169
184
|
- lib/clarification/response/search_response.rb
|
170
185
|
- lib/clarification/search.rb
|
186
|
+
- lib/clarification/train.rb
|
171
187
|
- lib/clarification/version.rb
|
172
188
|
homepage: https://github.com/nicholalexander/clarification
|
173
189
|
licenses:
|