Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active April 1, 2021 01:43
Show Gist options
  • Save symisc/40c911b599f1d86ee1b75d0829a3cfe4 to your computer and use it in GitHub Desktop.
Save symisc/40c911b599f1d86ee1b75d0829a3cfe4 to your computer and use it in GitHub Desktop.
Filter image uploads according to their NSFW score (Python Example) - https://pixlab.io/cmd?id=nsfw, https://dev.to/unqlite_db/filter-image-uploads-according-to-their-nsfw-score-15be
import requests
import json
# Target Image: Change to any link you want (Possibly adult) or switch to POST if you want to upload your image directly, refer to the sample set for more info.
img = 'https://i.redd.it/oetdn9wc13by.jpg'
# Your PixLab API Key - Get yours from https://pixlab.io/dashboard
key = 'PIXLAB_API_KEY'
# Blur an image according to its NSFW score
req = requests.get('https://api.pixlab.io/nsfw',params={'img':img,'key':key})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
elif reply['score'] < 0.5 :
print ("No adult content were detected on this picture")
else:
# Highly NSFW picture
print ("Censuring NSFW picture...")
# Call blur with the highest possible radius and sigma
req = requests.get('https://api.pixlab.io/blur',params={'img':img,'key':key,'rad':50,'sig':30})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
print ("Blurred Picture URL: "+ reply['link'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment