mirador 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +41 -2
- data/bin/mirador-client +51 -0
- data/lib/mirador/version.rb +1 -1
- data/lib/mirador.rb +19 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGFjNTRlZWI2MjFkYjI0YTk2MWFjYjNlMTM5ZmMzMmMxM2RmMjJmMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmM2YTU2ZTM1ZmZkNTc4OThlNTM1MzU1OGQzOWI1OGE2MzZhMThhZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTM5OTE3YjdhMjc2ZGIyY2YxNzVkOGRjODA1Mzc0Y2M0OGEzYzNjZWRlNGUw
|
10
|
+
NzkxMWZhMjk0MzQ0ZWU0NGE5NmQxZGZkMWQ1NTE5NDZjMjY2ZGU3NjY2NTZm
|
11
|
+
YzA4ZDk5OWIzODU1Mzk4OTQ5ODYwMTUwOGNkMGEyOTQxYzRkMGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmNkZDU1YzkyNzQwOWQwZjNlNTQzMTQ5MzhhMjdjZDE0YjI5OGQxMmZiNzRk
|
14
|
+
NjhhYTAzOWRkYzQ4ZjVjYTQzYTUxM2YwODE0ZDI3ODZlM2JjYzYwYmI5MzNk
|
15
|
+
ZmI4Y2Y0N2IwZGY3ZmNlN2Y1MGU5ZDIzMTI3ZjQzNTc5ZjRkYTg=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mirador
|
2
2
|
|
3
|
-
|
3
|
+
A simple Ruby client for the [mirador](http://mirador.im) Image moderation API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,42 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
There are really two basic methods available on the API. To get started, you need an API key, available from [mirador.im/join](http://mirador.im/join). If you have problems with the API or this client, please contact support@mirador.im.
|
22
|
+
|
23
|
+
### `Mirador::Client.classify_files(files) -> [Mirador::Result]`
|
24
|
+
|
25
|
+
This method takes a list of filenames and returns a list of `Mirador::Result` objects. See example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'mirador'
|
29
|
+
|
30
|
+
mc = Mirador::Client.new('your_key_here')
|
31
|
+
mc.classify_files('bathing-suit.jpg', 'nsfw-user-upload.png').each do |result|
|
32
|
+
puts "name: #{ result.name }, safe: #{ result.safe }, value: #{ result.value }"
|
33
|
+
end
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
### `Mirdor::Client.classify_urls(urls) -> [Mirador::Result]`
|
38
|
+
|
39
|
+
This method takes a list of urls and returns `Mirador::Result` objects. Identical to `classify_files`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'mirador'
|
43
|
+
|
44
|
+
mc.classify_urls('http://possibly-nsfw.com/cool.png', 'http://mysite.net/image/bad-picture.jpg').each do |result|
|
45
|
+
puts "name: #{ result.name }, safe: #{ result.safe }, value: #{ result.value }"
|
46
|
+
end
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
### `Mirador::Result`
|
51
|
+
|
52
|
+
The `Mirador::Result` class has 3 fields:
|
53
|
+
|
54
|
+
* `Result.name` - `string`, the filename or url for this request
|
55
|
+
* `Result.safe` - `bool`, a boolean indicating whether image contains adult content.
|
56
|
+
* `Result.value` - `float`, a number 0.0 - 1.0 indicating confidence of judgement
|
22
57
|
|
23
58
|
## Contributing
|
24
59
|
|
@@ -27,3 +62,7 @@ TODO: Write usage instructions here
|
|
27
62
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
63
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
64
|
5. Create new Pull Request
|
65
|
+
|
66
|
+
## Support
|
67
|
+
|
68
|
+
Please submit and bugs as issues, and don't hesitate to contact support@mirador.im with questions or issues.
|
data/bin/mirador-client
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#@author nickjacob (nick@mirador.im)
|
3
|
+
#####
|
4
|
+
require 'mirador'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
api_key = nil
|
8
|
+
OptionParser.new do |opt|
|
9
|
+
opt.banner = "usage: #{ File.basename($0) } -k api_key file|url [file|url...]"
|
10
|
+
|
11
|
+
opt.on('-k', '--api-key API KEY', 'api key') do |k|
|
12
|
+
api_key = k
|
13
|
+
end
|
14
|
+
|
15
|
+
end.parse!
|
16
|
+
|
17
|
+
if not api_key
|
18
|
+
puts "api key required"
|
19
|
+
exit(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
# url test
|
23
|
+
urlrxp = /^https?:\/\//
|
24
|
+
|
25
|
+
urls, files = [], []
|
26
|
+
ARGV.each do |x|
|
27
|
+
if x =~ urlrxp
|
28
|
+
urls << x
|
29
|
+
else
|
30
|
+
files << x
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# mirador client
|
35
|
+
client = Mirador::Client.new(api_key)
|
36
|
+
|
37
|
+
out = []
|
38
|
+
if urls and urls.length > 0
|
39
|
+
out += client.classify_urls(urls)
|
40
|
+
end
|
41
|
+
|
42
|
+
if files and files.length > 0
|
43
|
+
out += client.classify_files(files)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
out.each do |res|
|
48
|
+
puts "#{ res.to_s }"
|
49
|
+
end
|
50
|
+
|
51
|
+
|
data/lib/mirador/version.rb
CHANGED
data/lib/mirador.rb
CHANGED
@@ -6,10 +6,10 @@ module Mirador
|
|
6
6
|
API_BASE = "http://api.mirador.im/v1/"
|
7
7
|
|
8
8
|
class Result
|
9
|
+
attr_accessor :name, :safe, :value
|
9
10
|
|
10
11
|
def initialize name, data
|
11
12
|
@name = name
|
12
|
-
|
13
13
|
@safe = data['safe']
|
14
14
|
@value = data['value']
|
15
15
|
end
|
@@ -43,6 +43,7 @@ module Mirador
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def classify_urls urls
|
46
|
+
|
46
47
|
res = self.class.get(
|
47
48
|
"/v1/classify",
|
48
49
|
{
|
@@ -61,11 +62,27 @@ module Mirador
|
|
61
62
|
|
62
63
|
def classify_files files
|
63
64
|
processed = files.map do |f| self.process_file(f) end
|
65
|
+
return self.classify_encoded processed
|
66
|
+
end
|
64
67
|
|
68
|
+
|
69
|
+
def classify_raw_images imgs
|
70
|
+
processed = imgs.map { |i| Base64.encode(i).gsub("\n", '') }
|
71
|
+
return self.classify_encoded processed
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def process_file file
|
77
|
+
data = File.read(file)
|
78
|
+
Base64.encode64(data).gsub("\n", '')
|
79
|
+
end
|
80
|
+
|
81
|
+
def classify_encoded encoded
|
65
82
|
res = self.class.post(
|
66
83
|
"/v1/classify",
|
67
84
|
{
|
68
|
-
body: @options.merge({image:
|
85
|
+
body: @options.merge({image: encoded}),
|
69
86
|
headers: {'User-Agent' => 'Mirador Client v1.0/Ruby'},
|
70
87
|
}
|
71
88
|
)
|
@@ -81,11 +98,6 @@ module Mirador
|
|
81
98
|
return Result.parse_results(files, res['results'])
|
82
99
|
end
|
83
100
|
|
84
|
-
def process_file file
|
85
|
-
data = File.read(file)
|
86
|
-
Base64.encode64(data).gsub("\n", '')
|
87
|
-
end
|
88
|
-
|
89
101
|
end
|
90
102
|
|
91
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mirador
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -33,7 +33,8 @@ dependencies:
|
|
33
33
|
description: Interface to the Mirador Image Moderation API
|
34
34
|
email:
|
35
35
|
- nick@mirador.im
|
36
|
-
executables:
|
36
|
+
executables:
|
37
|
+
- mirador-client
|
37
38
|
extensions: []
|
38
39
|
extra_rdoc_files: []
|
39
40
|
files:
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- LICENSE.txt
|
43
44
|
- README.md
|
44
45
|
- Rakefile
|
46
|
+
- bin/mirador-client
|
45
47
|
- lib/mirador.rb
|
46
48
|
- lib/mirador/version.rb
|
47
49
|
- mirador.gemspec
|