badger_vision 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/badger_vision.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/badger_vision/client.rb +73 -0
- data/lib/badger_vision/config.rb +20 -0
- data/lib/badger_vision/configuration.rb +13 -0
- data/lib/badger_vision/request.rb +76 -0
- data/lib/badger_vision/version.rb +3 -0
- data/lib/badger_vision.rb +9 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c636bf2929c903d6c1336255a84fe382393bf519
|
4
|
+
data.tar.gz: eaf5e30be11105e195cfd51a50035d662258e61c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6af1789243660676a828354b901baf6f587e49058e49c8317dc106934cde4be70d9ec034388111f752f82197d81d726912f623ca0ba1e32c07d392449cde182
|
7
|
+
data.tar.gz: e31fe002a245324a7a176b932f5cd2a7a7320f7156dfb2012eb7a19debe306af0542da9f9840c108c52a45a22597871c8bf1978a0f622f918da131639241fd72
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
badger_vision (0.1.0)
|
5
|
+
faraday
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
faraday (0.14.0)
|
13
|
+
multipart-post (>= 1.2, < 3)
|
14
|
+
method_source (0.9.0)
|
15
|
+
multipart-post (2.0.0)
|
16
|
+
pry (0.11.3)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.1)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.1)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
badger_vision!
|
39
|
+
bundler (~> 1.16)
|
40
|
+
pry
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Badger Vision 🐼
|
2
|
+
|
3
|
+
Extract concepts and tags from images using badger vision. It's a wrapper
|
4
|
+
around the Places365 project allowing you to understand what landscape
|
5
|
+
information is available a given images
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'badger_vision'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install badger_vision
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You always need to pass a URL of the image to the service.
|
26
|
+
|
27
|
+
```
|
28
|
+
url = 'https://www.telegraph.co.uk/content/dam/Travel/Destinations/Asia/Maldives/Maldives%20lead-xlarge.jpg'
|
29
|
+
response = BadgerVision::Client.image_information(url: url)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
Your response has the following methods:
|
34
|
+
|
35
|
+
```
|
36
|
+
response.attributes
|
37
|
+
#=> ['natural light', 'open area', 'man-made', 'sunny', 'clouds', 'far-away horizon', 'swimming', 'boating', 'diving']
|
38
|
+
|
39
|
+
response.type
|
40
|
+
#=> 'outdoor'
|
41
|
+
|
42
|
+
scenes = info.scenes
|
43
|
+
|
44
|
+
scenes.first.name
|
45
|
+
#=> 'lagoon'
|
46
|
+
|
47
|
+
scenes.first.probability
|
48
|
+
#=> 0.299
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After 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.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Hendricius/badger_vision.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "badger_vision/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "badger_vision"
|
8
|
+
spec.version = BadgerVision::VERSION
|
9
|
+
spec.authors = ["Hendrik Kleinwaechter"]
|
10
|
+
spec.email = ["hendrik.kleinwaechter@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby wrapper for the Places365 image detection algorithm.}
|
13
|
+
spec.description = %q{Allows you to understand for a given image what is going on there.}
|
14
|
+
spec.homepage = "https://github.com/hendricius/badger_vision"
|
15
|
+
spec.licenses = ["MIT"]
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "pry", "~> 0"
|
28
|
+
|
29
|
+
spec.add_dependency "faraday", "~> 0"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "badger_vision"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "json"
|
3
|
+
require "pry"
|
4
|
+
require "badger_vision/config"
|
5
|
+
require "badger_vision/request"
|
6
|
+
|
7
|
+
module BadgerVision
|
8
|
+
class Client
|
9
|
+
def initialize(request_options: {})
|
10
|
+
@request_options = request_options
|
11
|
+
end
|
12
|
+
|
13
|
+
# Extract tags from a given image URL
|
14
|
+
def self.image_information(url)
|
15
|
+
new(request_options: {url: url}).image_information
|
16
|
+
end
|
17
|
+
|
18
|
+
def image_information
|
19
|
+
body = Request.post("cgi-bin/image.py", @request_options)
|
20
|
+
ImageInformationResponse.new(parse_response(body))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_response(body)
|
26
|
+
JSON.parse(body, symbolize_names: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
class ImageInformationResponse
|
30
|
+
def initialize(response)
|
31
|
+
@response = response || {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def attributes
|
35
|
+
@response.fetch(:attributes, []).split(",").map(&:strip)
|
36
|
+
end
|
37
|
+
|
38
|
+
def type
|
39
|
+
@response.fetch(:type, nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
def scenes
|
43
|
+
@response.fetch(:scenes, []).split(",").map(&:strip).map do |scene|
|
44
|
+
Scene.new(parse_scene(scene))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def parse_scene(scene)
|
51
|
+
name, probability = extract_scene_data(scene)
|
52
|
+
{
|
53
|
+
name: name,
|
54
|
+
probability: probability.to_f
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_scene_data(scene)
|
59
|
+
# format: lagoon (0.299)
|
60
|
+
scene.match(/^(\w*)\s\((.*)\)/)&.captures
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Scene
|
65
|
+
attr_reader :name, :probability
|
66
|
+
|
67
|
+
def initialize(name:, probability:)
|
68
|
+
@name = name
|
69
|
+
@probability = probability
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "badger_vision/configuration"
|
2
|
+
|
3
|
+
module BadgerVision
|
4
|
+
module Config
|
5
|
+
def configure
|
6
|
+
if block_given?
|
7
|
+
yield configuration
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# This exposes the configuration methods in global scope, so
|
17
|
+
# we can directly use those like: `BadgerVision.configuration`.
|
18
|
+
#
|
19
|
+
extend Config
|
20
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "badger_vision/config"
|
3
|
+
|
4
|
+
module BadgerVision
|
5
|
+
class Request
|
6
|
+
# Initialize a Request
|
7
|
+
#
|
8
|
+
# @param http_method [Symbol] HTTP verb as sysmbol
|
9
|
+
# @param endpoint [String] The relative API endpoint
|
10
|
+
# @param data [Hash] Attributes / Options as a Hash
|
11
|
+
#
|
12
|
+
def initialize(http_method, endpoint)
|
13
|
+
@data = data
|
14
|
+
@endpoint = endpoint
|
15
|
+
@http_method = http_method
|
16
|
+
end
|
17
|
+
|
18
|
+
# Make a HTTP Request
|
19
|
+
#
|
20
|
+
# @param options [Hash] Additonal options hash
|
21
|
+
# @return Hash
|
22
|
+
#
|
23
|
+
def request(options = {})
|
24
|
+
connection.send(http_method, api_endpoint, default_options.merge(options)).body
|
25
|
+
end
|
26
|
+
|
27
|
+
# Make a HTTP POST Request
|
28
|
+
#
|
29
|
+
# @param endpoint [String] The relative API endpoint
|
30
|
+
# @param options [Hash] The additional query params
|
31
|
+
# @return Hash
|
32
|
+
#
|
33
|
+
def self.post(endpoint, options = {})
|
34
|
+
new(:post, endpoint).request(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :client, :data, :http_method
|
40
|
+
|
41
|
+
def config
|
42
|
+
BadgerVision.configuration
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_options
|
46
|
+
{
|
47
|
+
random: Time.now.to_i * 1000,
|
48
|
+
data: nil,
|
49
|
+
date: Time.now.to_i * 1000,
|
50
|
+
demoimg: 0,
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def places_host
|
55
|
+
config.api_host
|
56
|
+
end
|
57
|
+
|
58
|
+
def api_endpoint
|
59
|
+
["", config.base_path, @endpoint].join("/").squeeze("/")
|
60
|
+
end
|
61
|
+
|
62
|
+
def faraday_options
|
63
|
+
{
|
64
|
+
url: places_host
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def connection
|
69
|
+
@connection ||= Faraday.new(faraday_options) do |faraday|
|
70
|
+
faraday.request :url_encoded # form-encode POST params
|
71
|
+
faraday.response :logger # log requests to STDOUT
|
72
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: badger_vision
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hendrik Kleinwaechter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Allows you to understand for a given image what is going on there.
|
84
|
+
email:
|
85
|
+
- hendrik.kleinwaechter@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- badger_vision.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/badger_vision.rb
|
101
|
+
- lib/badger_vision/client.rb
|
102
|
+
- lib/badger_vision/config.rb
|
103
|
+
- lib/badger_vision/configuration.rb
|
104
|
+
- lib/badger_vision/request.rb
|
105
|
+
- lib/badger_vision/version.rb
|
106
|
+
homepage: https://github.com/hendricius/badger_vision
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.6.13
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Ruby wrapper for the Places365 image detection algorithm.
|
130
|
+
test_files: []
|