sightengine 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sightengine.rb +6 -0
- data/lib/sightengine/api/base.rb +19 -0
- data/lib/sightengine/api/face_attributes.rb +51 -0
- data/lib/sightengine/api/nudity.rb +25 -0
- data/lib/sightengine/api/response.rb +13 -0
- data/lib/sightengine/api/scam.rb +17 -0
- data/lib/sightengine/api/wad.rb +25 -0
- data/lib/sightengine/client.rb +45 -0
- data/lib/sightengine/connection.rb +16 -0
- data/lib/sightengine/version.rb +3 -0
- data/sightengine.gemspec +30 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c52700aefc81d507cf3a25c3f9b91bc5c25d472a
|
4
|
+
data.tar.gz: 1cb342bed62b587449689fe30ecf49e63217dc4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dad55c114ea0dccda19f61b7a54d3146212ab76ae84e53030360ef8550531f4e0a57c3d9f614cd210bae458b7335ca71daccac4355dccd8befa2ac6fcd781a0e
|
7
|
+
data.tar.gz: fa8a5a1c13ed05b52445ef52421307f6c8bdcca2b4d12335c7be01839daad6fae2ac5ac4e5c16af71e91cee1d08e732039637c688b8f0de6da458243014c0206
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Léonard Hetsch <leo.hetsch@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Sightengine
|
2
|
+
|
3
|
+
Unofficial wrapper for the [Sightengine](https://sightengine.com/) API
|
4
|
+
which provides image moderation including nudity detection, scammer detection,
|
5
|
+
face attributes, and more.
|
6
|
+
|
7
|
+
Official API docs can be found here: https://sightengine.com/docs/reference
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sightengine'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install sightengine
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Configuration
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'sightengine'
|
31
|
+
|
32
|
+
client = Sightengine::Client.new(
|
33
|
+
api_user: 'your api user',
|
34
|
+
api_secret: 'your api secret'
|
35
|
+
)
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
### Nudity check
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
response = client.nudity("https://sightengine.com/assets/img/examples/example2.jpg")
|
43
|
+
|
44
|
+
response.raw_nudity? # false
|
45
|
+
response.partial_nudity? # false
|
46
|
+
response.safe? # true
|
47
|
+
```
|
48
|
+
|
49
|
+
### Face attributes
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
response = client.face_attributes("https://sightengine.com/assets/img/examples/example7.jpg")
|
53
|
+
|
54
|
+
response.faces.length # 1
|
55
|
+
face = response.faces.first
|
56
|
+
|
57
|
+
face.female? # true
|
58
|
+
face.male? # true
|
59
|
+
face.minor? # false
|
60
|
+
face.coordinates # [x1, y1, x2, y2] = [0.5156, 0.1936, 0.6922, 0.6207]
|
61
|
+
```
|
62
|
+
|
63
|
+
### Scam detection
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
response = client.scam("https://d3m9459r9kwism.cloudfront.net/img/examples/example-scam1-1000.jpg")
|
67
|
+
|
68
|
+
response.scam? # true
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
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.
|
74
|
+
|
75
|
+
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).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/leoht/sightengine.
|
80
|
+
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
85
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sightengine"
|
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
data/lib/sightengine.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sightengine
|
2
|
+
module Api
|
3
|
+
module Base
|
4
|
+
def check(image_url, models = [])
|
5
|
+
do_check(image_url, models)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def do_check(image_url, models)
|
11
|
+
connection.get build_uri('check.json') do |req|
|
12
|
+
req.headers[:content_type] = 'application/json'
|
13
|
+
req.params = default_params.merge({ url: image_url, models: models.join(",") })
|
14
|
+
p req.params.inspect
|
15
|
+
end.body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Sightengine
|
2
|
+
module Api
|
3
|
+
module FaceAttributes
|
4
|
+
class Face
|
5
|
+
attr_accessor :x1, :y1, :x2, :y2
|
6
|
+
attr_accessor :features
|
7
|
+
attr_accessor :attributes
|
8
|
+
|
9
|
+
def initialize(hash)
|
10
|
+
hash.each do |k, v|
|
11
|
+
send("#{k}=", v)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def coordinates
|
16
|
+
[x1, y1, x2, y2]
|
17
|
+
end
|
18
|
+
|
19
|
+
def female?(min_prob = 0.8)
|
20
|
+
attributes["female"].to_f > min_prob
|
21
|
+
end
|
22
|
+
|
23
|
+
def male?(min_prob = 0.8)
|
24
|
+
attributes["male"].to_f > min_prob
|
25
|
+
end
|
26
|
+
|
27
|
+
def minor?(min_prob = 0.8)
|
28
|
+
attributes["minor"].to_f > min_prob
|
29
|
+
end
|
30
|
+
|
31
|
+
def sunglasses?(min_prob = 0.8)
|
32
|
+
attributes["minor"].to_f > min_prob
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Response < ::Sightengine::Api::Response
|
37
|
+
attr_accessor :faces
|
38
|
+
|
39
|
+
def faces
|
40
|
+
(self.instance_variable_get("@faces") || []).map do |face|
|
41
|
+
Face.new(face)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def face_attributes(image_url)
|
47
|
+
Response.new(do_check(image_url, ["face-attributes"]))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sightengine
|
2
|
+
module Api
|
3
|
+
module Nudity
|
4
|
+
class Response < Sightengine::Api::Response
|
5
|
+
attr_accessor :nudity
|
6
|
+
|
7
|
+
def raw_nudity?(min_prob = 0.9)
|
8
|
+
nudity["raw"].to_f >= min_prob.to_f
|
9
|
+
end
|
10
|
+
|
11
|
+
def partial_nudity?(min_prob = 0.9)
|
12
|
+
nudity["partial"].to_f >= min_prob.to_f
|
13
|
+
end
|
14
|
+
|
15
|
+
def safe?(min_prob = 0.9)
|
16
|
+
nudity["safe"].to_f >= min_prob.to_f
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def nudity(image_url)
|
21
|
+
Response.new(do_check(image_url, ["nudity"]))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Sightengine
|
2
|
+
module Api
|
3
|
+
module Scam
|
4
|
+
class Response < ::Sightengine::Api::Response
|
5
|
+
attr_accessor :faces, :scam
|
6
|
+
|
7
|
+
def scam?(min_prob = 0.8)
|
8
|
+
scam["prob"].to_f > min_prob
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def scam(image_url)
|
13
|
+
Response.new(do_check(image_url, ["scam"]))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sightengine
|
2
|
+
module Api
|
3
|
+
module Wad
|
4
|
+
class Response < ::Sightengine::Api::Response
|
5
|
+
attr_accessor :weapon, :drugs, :alcohol
|
6
|
+
|
7
|
+
def weapon?(min_prob = 0.8)
|
8
|
+
weapon.to_f > min_prob
|
9
|
+
end
|
10
|
+
|
11
|
+
def alcohol?(min_prob = 0.8)
|
12
|
+
alcohol.to_f > min_prob
|
13
|
+
end
|
14
|
+
|
15
|
+
def drugs?(min_prob = 0.8)
|
16
|
+
drugs.to_f > min_prob
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def wad(image_url)
|
21
|
+
Response.new(do_check(image_url, ["wad"]))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "sightengine/api/response"
|
2
|
+
require "sightengine/api/base"
|
3
|
+
require "sightengine/api/nudity"
|
4
|
+
require "sightengine/api/wad"
|
5
|
+
require "sightengine/api/face_attributes"
|
6
|
+
require "sightengine/api/scam"
|
7
|
+
|
8
|
+
module Sightengine
|
9
|
+
class Client
|
10
|
+
include Sightengine::Connection
|
11
|
+
include Sightengine::Api::Base
|
12
|
+
include Sightengine::Api::Nudity
|
13
|
+
include Sightengine::Api::Wad
|
14
|
+
include Sightengine::Api::FaceAttributes
|
15
|
+
include Sightengine::Api::Scam
|
16
|
+
|
17
|
+
BASE_URI = 'https://api.sightengine.com'.freeze
|
18
|
+
|
19
|
+
VALID_OPTIONS = [
|
20
|
+
:api_user,
|
21
|
+
:api_secret,
|
22
|
+
:api_version
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
attr_accessor *VALID_OPTIONS
|
26
|
+
|
27
|
+
def initialize(**options)
|
28
|
+
options.merge(default_options).each do |opt, value|
|
29
|
+
send("#{opt}=", value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_uri(path, **params)
|
34
|
+
"#{BASE_URI}/#{self.api_version}/#{path}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_params
|
38
|
+
{ api_user: self.api_user, api_secret: self.api_secret }
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_options
|
42
|
+
{ api_version: '1.0' }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Sightengine
|
5
|
+
module Connection
|
6
|
+
def connection
|
7
|
+
Faraday::Connection.new({
|
8
|
+
headers: {'Content-Type' => 'application/json'}
|
9
|
+
}) do |conn|
|
10
|
+
conn.use Faraday::Request::UrlEncoded
|
11
|
+
conn.use FaradayMiddleware::ParseJson
|
12
|
+
conn.adapter(Faraday.default_adapter)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/sightengine.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sightengine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sightengine"
|
8
|
+
spec.version = Sightengine::VERSION
|
9
|
+
spec.authors = ["Léonard Hetsch"]
|
10
|
+
spec.email = ["leo.hetsch@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby wrapper for the Sightengine image moderation API}
|
13
|
+
spec.description = %q{Unofficial wrapper for the Sightengine API which provides image moderation including nudity detection, scammer detection, face attributes, and more.}
|
14
|
+
spec.homepage = "https://github.com/leoht/sightengine"
|
15
|
+
spec.license = "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_runtime_dependency "faraday", "~> 0.12"
|
25
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.11"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sightengine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Léonard Hetsch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Unofficial wrapper for the Sightengine API which provides image moderation
|
84
|
+
including nudity detection, scammer detection, face attributes, and more.
|
85
|
+
email:
|
86
|
+
- leo.hetsch@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/sightengine.rb
|
101
|
+
- lib/sightengine/api/base.rb
|
102
|
+
- lib/sightengine/api/face_attributes.rb
|
103
|
+
- lib/sightengine/api/nudity.rb
|
104
|
+
- lib/sightengine/api/response.rb
|
105
|
+
- lib/sightengine/api/scam.rb
|
106
|
+
- lib/sightengine/api/wad.rb
|
107
|
+
- lib/sightengine/client.rb
|
108
|
+
- lib/sightengine/connection.rb
|
109
|
+
- lib/sightengine/version.rb
|
110
|
+
- sightengine.gemspec
|
111
|
+
homepage: https://github.com/leoht/sightengine
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.5
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Ruby wrapper for the Sightengine image moderation API
|
135
|
+
test_files: []
|