Miscellaneous
This is the description of our different miscellaneous endpoints for the API.
Sensitive Content Detection (/sensitive_content_detection)
Detect if image contains sensitive content (NSFW or NSFL)
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as image_file:
# Read the image, encode it in base64, and convert to string
return base64.b64encode(image_file.read()).decode('utf-8')
url = f"https://gateway.ezml.io/api/v1/functions/sensitive_content_detection"
payload = {
"image": image_to_base64("<path to image>"),
}
headers = {
"Authorization": "Bearer <token from /auth>"
}
res = requests.post(url, json=payload, headers=headers).json()["result"]
print("Chance of being NSFW: ", res["not_work_safe"] * 100 + "%")
print("Chance of being NSFL: ", res["not_life_safe"] * 100 + "%")
Product Ad Inpainting (/ad_inpaint)
Put product in an image into a generated background defined by a prompt
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as image_file:
# Read the image, encode it in base64, and convert to string
return base64.b64encode(image_file.read()).decode('utf-8')
url = f"https://gateway.ezml.io/api/v1/functions/ad_inpaint"
payload = {
"image": image_to_base64("<path to image>"),
"prompt": "The product in a solid white background on a table", # define the prompt for the surrounding environment
"negative_prompt": "Ugly, messy, dirty background", # define what the image shouldn't have
}
headers = {
"Authorization": "Bearer <token from /auth>"
}
res = requests.post(url, json=payload, headers=headers)
res = res.json()
with open("test.png", "wb") as f: # write resulting image to file
f.write(base64.b64decode(res["result"]))
Last updated on November 14, 2023