sfwhttps://api.pixlab.io/sfw
Description
Detect whether a given image is suitable for work (does not contain adult content). This the opposite of what the nsfw endpoint does.
HTTP Methods
GET, POST
Request Parameters
Required
Fields | Type | Description |
---|---|---|
img | URL | Input image URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. Only JPEG & PNG file format are allowed. Call convert if you have a different image format. |
key | String | Your PixLab API Key. |
POST Request Body (If you plan to use POST instead of a simple GET request)
Allowed Content-Type:
multipart/form-data
application/json
Use multipart/form-data if you want to upload your image directly. If you are using JSON, then your image must be already uploaded somewhere. Call store if you want to upload an image before invoking this endpoint.
Response
application/json
This command always return a JSON object after each call. The field of interest here is the score value. The more this value approaches 1, the more your picture is pretty safe. The following are the JSON fields returned in response body:
Fields | Type | Description |
---|---|---|
status | Integer | Status code 200 indicates success, any other code indicates failure. |
score | Float | SFW score value which is set between 0 .. 1. The more this value approaches 1,the more your image is pretty safe & does not contain any adult content. |
error | String | Error message if status != 200. |
Python Example
import requests
import json
req = requests.get('https://api.pixlab.io/sfw',params={'img':'https://i.redd.it/oetdn9wc13by.jpg','key':'My_PixLab_Key'})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
elif reply['score'] > 0.5 :
print ("This image is pretty safe & does not appear to have any adult content!")
else:
print ("This picture is highly NSFW & may contain adult content, perhaps censure it?")
#call api.pixlab.io/blur, api.pixlab.io/encrypt to make a censured version of the picture