Remove Background
Check out the Remove Background API reference for full details. Here's how you can remove the background of a file:
import requests
url = "https://playground.com/api/models/external/v1/remove-background"
def get_base64_from_file(filename):
with open(filename, "rb") as f:
return base64.b64encode(f.read()).decode()
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {
"image": get_base64_from_file("image_with_background.png"),
}
response = requests.post(url, headers=headers, json=data)
Updated 8 months ago