|
1 | | -Sightengine Python Client |
2 | | -=============== |
3 | 1 |
|
4 | | -Nudity detection and moderation - Python library to connect to the Sightengine API |
| 2 | +# About |
5 | 3 |
|
6 | | -About |
7 | | ------ |
| 4 | +Use the Sightengine Moderation API to instantly moderate images and videos. See http://sightengine.com for more information. |
8 | 5 |
|
9 | | -Use the Sightengine nudity API to instantly moderate adult content in user-submitted photos. See http://sightengine.com for more information. |
| 6 | +Before starting, please make sure you have created an account on https://sightengine.com |
10 | 7 |
|
| 8 | +# Initialize the client |
11 | 9 |
|
12 | | -Instructions |
13 | | ------- |
| 10 | +You will need your API USER and API SECRET to initialize the client. You can find both of them on your Sightengine account. |
| 11 | +```python |
| 12 | +from sightengine.client import SightengineClient |
| 13 | +client = SightengineClient("YOUR_API_USER", "YOUR_API_SECRET") |
| 14 | +``` |
14 | 15 |
|
15 | | -1. Create an account on http://sightengine.com, you will get your own API_USER and API_SECRET values |
16 | | -2. Import the Sightengine package and use the below examples to start using the API |
| 16 | +# Moderate an image |
17 | 17 |
|
| 18 | +The API accepts both standard still images: JPEG, PNG, WEBP etc. and multi-frame GIF images. |
18 | 19 |
|
19 | | -Examples |
20 | | --------- |
| 20 | +Several moderation engines are available for you to choose from (nudity detection, inappropriate content detection etc...). Please refer to the documentation for more. |
21 | 21 |
|
22 | | -Import and create the SightengineClient object |
| 22 | +## Moderate an image through a public URL: |
23 | 23 |
|
24 | | - from sightengine import client |
25 | | - sightengine_client = client.SightengineClient("YOUR_API_USER", "YOUR_API_SECRET") |
| 24 | +```python |
| 25 | +# Detect nudity in an image |
| 26 | +output = client.check('nudity').image('http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg') |
26 | 27 |
|
27 | | -Moderate an image accessible through a public URL: |
| 28 | +# Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type |
| 29 | +output = client.check('nudity, type, properties, wad, face').image('http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg') |
| 30 | +``` |
28 | 31 |
|
29 | | - output = sightengine_client.check_nudity("http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg") |
30 | | - print output |
| 32 | +## Moderate a local image: |
| 33 | +```python |
| 34 | +# Detect nudity in an image |
| 35 | +output = client.check('nudity').image('/full/path/to/image.jpg') |
31 | 36 |
|
| 37 | +# Detect nudity, weapons, alcohol, drugs and faces in an image, along with image properties and type |
| 38 | +output = client.check('nudity, type, properties, wad, face').image('/full/path/to/image.jpg') |
| 39 | +``` |
32 | 40 |
|
33 | | -Moderate a local image: |
| 41 | +# Video and Stream Moderation |
| 42 | +The first step to detect nudity in a video stream is to submit the video stream to the API. |
34 | 43 |
|
35 | | - output = sightengine_client.check_nudity("/full/path/to/image.jpg") |
36 | | - print output |
| 44 | +```python |
| 45 | +client.check('nudity').video('http://www.quirksmode.org/html5/videos/big_buck_bunny.webm', 'https://example.com/yourcallback') |
| 46 | +``` |
| 47 | + |
| 48 | +# Feedback |
| 49 | +In order to report a misclassification, you need to report the image that was misclassified, the model that was run on this image (models are nudity, face, type, wad), and the correct class of the image. |
| 50 | + |
| 51 | +For each model, there are different classes that you may report. Here are the details: |
| 52 | + |
| 53 | +The nudity model has 3 classes: |
| 54 | + * raw: corresponding to raw nudity |
| 55 | + * partial: corresponding to partial nudity |
| 56 | + * safe: corresponding to no nudity |
| 57 | + |
| 58 | +The face model has 3 classes: |
| 59 | + * none |
| 60 | + * single |
| 61 | + * multiple |
| 62 | + |
| 63 | +The type model has 2 classes: |
| 64 | +* photo |
| 65 | +* illustration |
| 66 | + |
| 67 | +The wad model has 3 classes: |
| 68 | +* no-weapons |
| 69 | +* weapons |
| 70 | +* no-alcohol |
| 71 | +* alcohol |
| 72 | +* no-drugs |
| 73 | +* drugs |
| 74 | + |
| 75 | +```python |
| 76 | +client.feedback(model, class,image) |
| 77 | +``` |
| 78 | +Example of feedback on a local image: |
| 79 | +```python |
| 80 | +client.feedback("nudity","safe", "/full/path/to/image.jpg") |
| 81 | +client.feedback("type","illustration", "/full/path/to/image.jpg") |
| 82 | +client.feedback("nudity","raw", "/full/path/to/image.jpg") |
| 83 | +``` |
| 84 | +Example of feedback through a public URL:: |
| 85 | +```python |
| 86 | +client.feedback("nudity","safe", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg") |
| 87 | +client.feedback("type","illustration", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg") |
| 88 | +client.feedback("nudity","raw", "http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg") |
| 89 | +``` |
0 commit comments