
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
yandex_image_moderation
Advanced tools
This gem provides a class for access to Yandex Image Moderation API (https://imagemoderation.yandexdatafactory.com/)
Add this line to your application's Gemfile:
gem 'yandex_image_moderation'
And then execute:
$ bundle
Or install it yourself as:
$ gem install yandex_image_moderation
For Yandex API access you have to provide an API key. Do it by calling config method of the YandexImageModeration class:
YandexImageModeration.config do |c|
c.token = 'your_API_key'
end
If you use Rails, this configuration would probably go into a proper initializer.
In some cases you may need to change URL of the API (i.e. when you use not the SAAS API, but a docker version on your own server). To override the standard URL just add url attribute to the config. In the URL provide the path to the moderate service, do not add any parameters like ?model=moderate...
YandexImageModeration.config do |c|
c.url = 'http://your_server/path_to/moderate'
c.token = 'your_API_key'
end
To moderate an image (remember: Yandex API works with JPEG only) just call a moderate methods with a path to the image file as a parameter:
answer = YandexImageModeration.moderate('/var/www/uploads/test.jpg')
# => #<YandexImageModeration::Result:0x0055ae52e8a7a0
@data=
{"status"=>"ok",
"revision"=>"33e3dfd4d",
"revisionDate"=>"2016-08-29 17:06:06 +0300",
"result"=>
{"classification"=>
{"gender"=>
{"predictedClass"=>"male",
"scores"=>{"female"=>0.0752159, "male"=>0.924784}},
"moderation"=>
{"predictedClass"=>"other",
"scores"=>
{"other"=>0.998316,
"erotic"=>1.01304e-05,
"inappropriateOrChild"=>0.00149277,
"approvedPersonNotChild"=>3.49765e-05,
"many"=>0.000146203}},
"pornography"=>
{"predictedClass"=>"other",
"scores"=>{"explicit"=>9.50646e-09, "other"=>0.99999999049354}},
"ad"=>
{"predictedClass"=>"not_ads",
"scores"=>{"ads"=>0.0229261, "not_ads"=>0.977074}}}}},
@result=
{"gender"=>
{"predictedClass"=>"male",
"scores"=>{"female"=>0.0752159, "male"=>0.924784}},
"moderation"=>
{"predictedClass"=>"other",
"scores"=>
{"other"=>0.998316,
"erotic"=>1.01304e-05,
"inappropriateOrChild"=>0.00149277,
"approvedPersonNotChild"=>3.49765e-05,
"many"=>0.000146203}},
"pornography"=>
{"predictedClass"=>"other",
"scores"=>{"explicit"=>9.50646e-09, "other"=>0.99999999049354}},
"ad"=>
{"predictedClass"=>"not_ads",
"scores"=>{"ads"=>0.0229261, "not_ads"=>0.977074}}},
@status="ok">
You can check if the request was successful or not:
answer.good?
# => true
answer.bad?
# => false
answer.status
# => "ok"
Then you can access to the resulting data directly through the result attribute:
answer.result['ad']['predictedClass']
# => "not_ads"
Also you can check either the image was classified as porn, erotic or ad and get scores for the classifications (scores are between 0 and 1):
answer.porn?
# => false
answer.erotic?
# => false
answer.ad?
# => false
answer.porn_score
# => 9.50646e-09
answer.erotic_score
# => 1.01304e-05
answer.ad_score
# => 0.0229261
And another one shortcut is provided - for getting predicted class during moderation:
answer.predicted_class
# => "other"
For a clarification on the returned data, predicted classes and scores please consult Yandex Image Moderation API documentation.
Bug reports and pull requests are welcome on GitHub at https://github.com/tgrave/yandex_image_moderation.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that yandex_image_moderation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.