Skip to content

Commit cb895d5

Browse files
committed
Initial commit
0 parents  commit cb895d5

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sightengine/*.pyc

README.MD

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Sightengine Python Client
2+
===============
3+
4+
Nudity detection and moderation - Python library to connect to the Sightengine API
5+
6+
About
7+
-----
8+
9+
Use the Sightengine nudity API to instantly moderate adult content in user-submitted photos. See http://sightengine.com for more information.
10+
11+
12+
Instructions
13+
------
14+
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
17+
3. Create a SightengineClient object and use it as shown in the example
18+
19+
20+
Examples
21+
--------
22+
23+
Moderate an image accessible through a public URL:
24+
25+
from sightengine import client
26+
sightengine_client = client.SightengineClient("YOUR_API_USER", "YOUR_API_SECRET")
27+
output = sightengine_client.check_nudity("http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg")
28+
print output
29+
30+
31+
Moderate a local image:
32+
33+
from sightengine import client
34+
sightengine_client = client.SightengineClient("YOUR_API_USER", "YOUR_API_SECRET")
35+
output = sightengine_client.check_nudity("/full/path/to/image.jpg")
36+
print output

example.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from sightengine import client
4+
5+
# Once you create an account on sightengine.com, you will get your own API user and API secret values
6+
# Please do not forget to replace them here
7+
sightengine_client = client.SightengineClient("YOUR_API_USER", "YOUR_API_SECRET")
8+
9+
# Call the Sightengine servers to check for nudity. You can either pass a public URL or a local path. This call will raise an HTTPError if the HTTP connection fails
10+
output = sightengine_client.check_nudity("http://img09.deviantart.net/2bd0/i/2009/276/c/9/magic_forrest_wallpaper_by_goergen.jpg")
11+
12+
print output

sightengine/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Copyright (c) 2015 Sightengine
4+
http://www.sightengine.com/
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+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
"""

sightengine/client.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Copyright (c) 2015 Sightengine
4+
http://www.sightengine.com/
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+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
"""
21+
22+
import requests
23+
import json
24+
25+
class SightengineClient(object):
26+
27+
def __init__(self, api_user, api_secret):
28+
"""
29+
Sightengine Client initialization
30+
"""
31+
self._api_user = api_user
32+
self._api_secret = api_secret
33+
34+
@property
35+
def api_user(self):
36+
return self._api_user
37+
38+
@property
39+
def api_secret(self):
40+
return self._api_secret
41+
42+
def check_nudity(self, image):
43+
endpoint = 'http://api.sightengine.com'
44+
version = '1.0'
45+
url = endpoint+'/'+version+'/nudity.json'
46+
47+
if image[:7].lower()=='http://' or image[:8].lower()=='https://':
48+
r = requests.post(url, data={'url':image, 'api_user':self._api_user, 'api_secret':self._api_secret})
49+
else:
50+
r = requests.post(url, files={'photo': open(image, 'rb')}, data={'api_user':self._api_user, 'api_secret':self._api_secret})
51+
52+
r.raise_for_status()
53+
54+
output = json.loads(r.text)
55+
56+
return output

0 commit comments

Comments
 (0)