AI Backgrounds Competitors Benchmark (Claid.ai, Phot.ai, Bria.ai)
On this page you will find a comparison of our AI Backgrounds against some of our competitors.
Feature Comparison
Photoroom API | Claid.ai API | Phot.ai API | Bria.ai API | |
---|---|---|---|---|
Pricing | €0.10 per image | from $0.20 per image | from $0.18 per image | from $0.08 per image |
Response time | ~5 seconds | ~15 seconds | ~35 seconds | ~20 seconds |
# of API calls required | 1 call | 2 calls | 1 call | 1 call |
Supports a different aspect ratio than that of the input image | Yes | Yes | No | No |
Supports sending an image file | Yes | Yes | No | Yes |
Supports sending an image URL | Yes | Yes | Yes | Yes |
Supports setting the RNG seed | Yes | No | No | Yes |
Result Comparison
Food Images
Original Image | |
Prompt | the image displays a plate of vegetables with succulents in the background. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | a chocolate cupcake with blue frosting on a white marbled tray, with a pastel coloured table in the background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) | This image failed to process |
Original Image | |
Prompt | a plate of chicken wings and dipping sauces on a black scampered wooden table. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a piece of bread with avocado and greens on top bathed in a golden light. It has been captured professionally, emphasizing the warm tones and gleaming highlights. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a bowl with bread and vegetables foregrounded against a breathtaking mountain sunset. The object is set against a picturesque scene of a mountain during sunset. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Cosmetic Images
Original Image | |
Prompt | the image displays a bottle with a pink substance surrounded by cherry blossom. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a tube of false lashes in a bathroom. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays an orange plastic bottle with a pump top on a tropical beach on a bright day with a slightly blurred background of the ocean |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a tube of lotion on a cream marble countertop. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a spray bottle sitting on top on a table with a beautiful orange yellow sunset where the clouds are brightly lit from the sunset and a field is in the background slightly blurry |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Apparel Images
Original Image | |
Prompt | the image displays a jacket hanging on a wall standing against a baby blue background. The background is plain, textureless, doesn't have any discernible objects or patterns, and its color is baby blue |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | a baseball cap on a baseball field, with a bright sun in the background |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | a crocheted poncho on a fluffy blanket, with a soft green grass field in the background |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a group of three people standing set against an autumn-themed backdrop, captivating the essence of fall season. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image illustrates a person walking set against a breathtaking mountain view. It exudes a professionalism in composition and performance. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Jewelry Images
Original Image | |
Prompt | the image displays a ring with a pink stone on a cream marble countertop. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | a long necklace on a black velvet cushion, with a cream stone wall in the background |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a pair of earrings on a green marble countertop. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a pair of wedding rings sitting next to each other on a concrete countertop. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a necklace in a cozy home. The image features a minimalistic and professional looking background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
People Images
Original Image | |
Prompt | a person standing with their eyes closed on an old, twisted brick wall, with a grey field in the background |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image features a person walking on a boulder with a breathtaking mountain view in the background. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a person wearing glasses and a green shirt with New York in the background. The overall scenery in the background is typical and instantly transports you to New York |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a person riding a skateboard set against an autumn-themed backdrop, captivating the essence of fall season. |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Original Image | |
Prompt | the image displays a person holding a suit case on a tropical beach on a bright day with a slightly blurred background of the ocean |
Photoroom API (response time: ~5 seconds) | |
Claid.ai API (response time: ~15 seconds) | |
Phot.ai API (response time: ~35 seconds, doesn't support changing the aspect ratio) | |
Bria.ai API (response time: ~20 seconds, doesn't support changing the aspect ratio) |
Reproducing the results
If you want to reproduce the results of this benchmark, here are the Python scripts that were used to generate the images.
import os
import requests
import concurrent.futures
API_KEY = "YOUR_PHOTOROOM_API_KEY"
SEEDS = [117879368, 55994449, 48672244, 65080068]
def process_image(image_url, prompt, variant_index, output_image_path):
try:
url = "https://image-api.photoroom.com/v2/edit"
params = {
"imageUrl": image_url,
"referenceBox": "originalImage",
"outputSize": "1024x1024",
"background.prompt": prompt,
"background.negativePrompt": "oversaturated, ugly, 3d, render, cartoon, grain, low-res, kitsch, text, lens, camera",
"background.seed": SEEDS[variant_index]
}
headers = {
"x-api-key": API_KEY,
"pr-ai-background-model-version": "3"
}
response = requests.get(url, params=params, headers=headers)
response.raise_for_status()
with open(output_image_path, 'wb') as f:
f.write(response.content)
print(f"Image downloaded and saved to {output_image_path}")
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def iterate_over(image_urls, prompts, file_names, result_directory):
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
root = os.getcwd()
for image_url, prompt, file_name in zip(image_urls, prompts, file_names):
file_path = os.path.join(root, file_name)
for variant in range(0, 5):
result_file_name = f"photoroom-{file_name}-variant_{variant+1}.png"
result_path = os.path.join(result_directory, result_file_name)
executor.submit(process_image, image_url, prompt, variant, result_path)
if __name__ == "__main__":
# FOOD
FOOD_IMAGES_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F1.jpg?alt=media&token=850ab5be-a503-40f1-a270-c7cdcc62bdeb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F2.png?alt=media&token=9c6e5512-efb8-47bc-b45d-01cb5b00b698",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F3.jpg?alt=media&token=04851dba-83bc-4d24-9549-ad029a838c33",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F4.jpeg?alt=media&token=191746c4-c528-4e2f-9e04-e1cac0b8d4b9",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F5.jpeg?alt=media&token=97421dcf-14b0-4353-913e-03428341e274",
]
FOOD_PROMPTS = [
"the image displays a plate of vegetables with succulents in the background. The image features a minimalistic and professional looking background.",
"a chocolate cupcake with blue frosting on a white marbled tray, with a pastel coloured table in the background",
"a plate of chicken wings and dipping sauces on a black scampered wooden table.",
"the image displays a piece of bread with avocado and greens on top bathed in a golden light. It has been captured professionally, emphasizing the warm tones and gleaming highlights.",
"the image displays a bowl with bread and vegetables foregrounded against a breathtaking mountain sunset. The object is set against a picturesque scene of a mountain during sunset.",
]
FOOD_OUTPUT_DIRECTORY = "./output-photoroom/food/"
if not os.path.exists(FOOD_OUTPUT_DIRECTORY):
os.makedirs(FOOD_OUTPUT_DIRECTORY)
iterate_over(image_urls=FOOD_IMAGES_URLS, prompts=FOOD_PROMPTS, file_names=list(map(str, range(1, len(FOOD_IMAGES_URLS) + 1))), result_directory=FOOD_OUTPUT_DIRECTORY)
# COSMETIC
COSMETIC_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F1.jpeg?alt=media&token=837a3a2c-4621-44bc-84d7-ca1bafd7dad7",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F2.jpeg?alt=media&token=9327b3b6-68a6-4106-88cc-978afa5c048e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F3.png?alt=media&token=6c25d2aa-4a11-4b00-bac6-b98f59289b5c",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F4.jpg?alt=media&token=be6075e1-b754-4f98-8937-cba8d234942d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F5.jpg?alt=media&token=982083a1-b8df-40f7-88cc-c9185670f162",
]
COSMETIC_PROMPTS = [
"the image displays a bottle with a pink substance surrounded by cherry blossom. The image features a minimalistic and professional looking background.",
"the image displays a tube of false lashes in a bathroom. The image features a minimalistic and professional looking background.",
"the image displays an orange plastic bottle with a pump top on a tropical beach on a bright day with a slightly blurred background of the ocean",
"the image displays a tube of lotion on a cream marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a spray bottle sitting on top on a table with a beautiful orange yellow sunset where the clouds are brightly lit from the sunset and a field is in the background slightly blurry",
]
COSMETIC_OUTPUT_DIRECTORY = "./output-photoroom/cosmetic/"
if not os.path.exists(COSMETIC_OUTPUT_DIRECTORY):
os.makedirs(COSMETIC_OUTPUT_DIRECTORY)
iterate_over(image_urls=COSMETIC_IMAGE_URLS, prompts=COSMETIC_PROMPTS, file_names=list(map(str, range(1, len(COSMETIC_IMAGE_URLS) + 1))), result_directory=COSMETIC_OUTPUT_DIRECTORY)
# APPAREL
APPAREL_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F1.jpeg?alt=media&token=462bd079-f084-4a97-bdf5-51e1ea6454a3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F2.jpg?alt=media&token=7666a271-93c8-4fa5-bf46-e550f2832189",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F3.jpg?alt=media&token=3551ca21-e31a-4076-b810-1bc0aacbaceb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F4.jpg?alt=media&token=4a2d0c5d-b44a-479f-bc35-64fcc3d3d366",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F5.jpeg?alt=media&token=4624dafe-959b-4bfc-b230-7785780abcf7",
]
APPAREL_PROMPTS = [
"the image displays a jacket hanging on a wall standing against a baby blue background. The background is plain, textureless, doesn't have any discernible objects or patterns, and its color is baby blue",
"a baseball cap on a baseball field, with a bright sun in the background",
"a crocheted poncho on a fluffy blanket, with a soft green grass field in the background",
"the image displays a group of three people standing set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image illustrates a person walking set against a breathtaking mountain view. It exudes a professionalism in composition and performance.",
]
APPAREL_OUTPUT_DIRECTORY = "./output-photoroom/apparel/"
if not os.path.exists(APPAREL_OUTPUT_DIRECTORY):
os.makedirs(APPAREL_OUTPUT_DIRECTORY)
iterate_over(image_urls=APPAREL_IMAGE_URLS, prompts=APPAREL_PROMPTS, file_names=list(map(str, range(1, len(APPAREL_IMAGE_URLS) + 1))), result_directory=APPAREL_OUTPUT_DIRECTORY)
# JEWELRY
JEWELRY_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F1.jpg?alt=media&token=0afec946-38cf-4773-a96a-d0c158358557",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F2.jpg?alt=media&token=9b93ee57-9343-4611-8156-76c512149002",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F3.jpg?alt=media&token=925a455c-1b58-469d-95c7-7db4ff5ac61e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F4.jpg?alt=media&token=c694560d-951d-4fe5-8390-a4c5df846f51",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F5.jpg?alt=media&token=38205d4d-ce4f-4168-9a91-94d872aed3fe",
]
JEWELRY_PROMPTS = [
"the image displays a ring with a pink stone on a cream marble countertop. The image features a minimalistic and professional looking background.",
"a long necklace on a black velvet cushion, with a cream stone wall in the background",
"the image displays a pair of earrings on a green marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a pair of wedding rings sitting next to each other on a concrete countertop. The image features a minimalistic and professional looking background.",
"the image displays a necklace in a cozy home. The image features a minimalistic and professional looking background.",
]
JEWELRY_OUTPUT_DIRECTORY = "./output-photoroom/jewelry/"
if not os.path.exists(JEWELRY_OUTPUT_DIRECTORY):
os.makedirs(JEWELRY_OUTPUT_DIRECTORY)
iterate_over(image_urls=JEWELRY_IMAGE_URLS, prompts=JEWELRY_PROMPTS, file_names=list(map(str, range(1, len(JEWELRY_IMAGE_URLS) + 1))), result_directory=JEWELRY_OUTPUT_DIRECTORY)
# PEOPLE
PEOPLE_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F1.jpg?alt=media&token=5b57a70d-e94d-4056-8e48-2b8a2c296028",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F2.jpg?alt=media&token=f0e8a0bb-9fd7-4cc3-bd90-b5655321d46d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F3.jpg?alt=media&token=37ade83a-611e-4346-b4fe-5ee484f69ea3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F4.jpg?alt=media&token=3569a732-9be2-4b2d-b685-c55a1093fca8",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F5.jpg?alt=media&token=38875d9b-8f48-4bec-a30a-ca10be2b86d5",
]
PEOPLE_PROMPTS = [
"a person standing with their eyes closed on an old, twisted brick wall, with a grey field in the background",
"the image features a person walking on a boulder with a breathtaking mountain view in the background.",
"the image displays a person wearing glasses and a green shirt with New York in the background. The overall scenery in the background is typical and instantly transports you to New York",
"the image displays a person riding a skateboard set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image displays a person holding a suit case on a tropical beach on a bright day with a slightly blurred background of the ocean",
]
PEOPLE_OUTPUT_DIRECTORY = "./output-photoroom/people/"
if not os.path.exists(PEOPLE_OUTPUT_DIRECTORY):
os.makedirs(PEOPLE_OUTPUT_DIRECTORY)
iterate_over(image_urls=PEOPLE_IMAGE_URLS, prompts=PEOPLE_PROMPTS, file_names=list(map(str, range(1, len(PEOPLE_IMAGE_URLS) + 1))), result_directory=PEOPLE_OUTPUT_DIRECTORY)
Please note that:
Claid.ai requires to make a first API call to remove the original background, then make a second call to generate the new background
Claid.ai doesn't support providing the seed of the random number generator, so you will not get exactly the same results than the ones shown above
import os
import requests
API_KEY = "YOUR_CLAID_AI_API_KEY"
def remove_background(input_image_url):
try:
url = "https://api.claid.ai/v1-beta1/image/edit"
payload = {
"input": input_image_url,
"operations": {
"background": {
"remove": True
},
"resizing": {
"width": 1024,
"height": 1024,
"fit": "bounds"
}
},
"output": {
"format": "png"
}
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
tmp_url = data['data']['output']['tmp_url']
print(f"Background Removed: {tmp_url}")
return tmp_url
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def generate_background(input_image_url, prompt, input_file_name, output_directory):
try:
url = "https://api.claid.ai/v1-ea/scene/create"
payload = {
"object": {
"image_url": input_image_url,
"placement_type": "original"
},
"scene": {
"prompt": prompt,
"negative_prompt": "oversaturated, ugly, 3d, render, cartoon, grain, low-res, kitsch, text, lens, camera"
}
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
for index, variant in zip(range(1, 5), data['data']['output']):
variant_url = variant['tmp_url']
response = requests.get(variant_url)
response.raise_for_status() # To ensure the request was successful
variant_file_name = os.path.join(output_directory, f"claid-ai-{input_file_name}-variant_{index}.png")
with open(variant_file_name, 'wb') as f:
f.write(response.content)
print(f"Image downloaded and saved to {variant_file_name}")
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def process_image(input_image_url, prompt, input_file_name, output_directory):
background_removed_url = remove_background(input_image_url)
generate_background(background_removed_url, prompt, input_file_name, output_directory)
def iterate_over(image_urls, prompts, file_names, result_directory):
for image_url, prompt, file_name in zip(image_urls, prompts, file_names):
process_image(image_url, prompt, file_name, result_directory)
if __name__ == "__main__":
# FOOD
FOOD_IMAGES_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F1.jpg?alt=media&token=850ab5be-a503-40f1-a270-c7cdcc62bdeb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F2.png?alt=media&token=9c6e5512-efb8-47bc-b45d-01cb5b00b698",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F3.jpg?alt=media&token=04851dba-83bc-4d24-9549-ad029a838c33",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F4.jpeg?alt=media&token=191746c4-c528-4e2f-9e04-e1cac0b8d4b9",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F5.jpeg?alt=media&token=97421dcf-14b0-4353-913e-03428341e274",
]
FOOD_PROMPTS = [
"the image displays a plate of vegetables with succulents in the background. The image features a minimalistic and professional looking background.",
"a chocolate cupcake with blue frosting on a white marbled tray, with a pastel coloured table in the background",
"a plate of chicken wings and dipping sauces on a black scampered wooden table.",
"the image displays a piece of bread with avocado and greens on top bathed in a golden light. It has been captured professionally, emphasizing the warm tones and gleaming highlights.",
"the image displays a bowl with bread and vegetables foregrounded against a breathtaking mountain sunset. The object is set against a picturesque scene of a mountain during sunset.",
]
FOOD_OUTPUT_DIRECTORY = "./output-claid-ai/food/"
if not os.path.exists(FOOD_OUTPUT_DIRECTORY):
os.makedirs(FOOD_OUTPUT_DIRECTORY)
iterate_over(image_urls=FOOD_IMAGES_URLS, prompts=FOOD_PROMPTS, file_names=list(map(str, range(1, len(FOOD_IMAGES_URLS) + 1))), result_directory=FOOD_OUTPUT_DIRECTORY)
# COSMETIC
COSMETIC_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F1.jpeg?alt=media&token=837a3a2c-4621-44bc-84d7-ca1bafd7dad7",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F2.jpeg?alt=media&token=9327b3b6-68a6-4106-88cc-978afa5c048e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F3.png?alt=media&token=6c25d2aa-4a11-4b00-bac6-b98f59289b5c",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F4.jpg?alt=media&token=be6075e1-b754-4f98-8937-cba8d234942d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F5.jpg?alt=media&token=982083a1-b8df-40f7-88cc-c9185670f162",
]
COSMETIC_PROMPTS = [
"the image displays a bottle with a pink substance surrounded by cherry blossom. The image features a minimalistic and professional looking background.",
"the image displays a tube of false lashes in a bathroom. The image features a minimalistic and professional looking background.",
"the image displays an orange plastic bottle with a pump top on a tropical beach on a bright day with a slightly blurred background of the ocean",
"the image displays a tube of lotion on a cream marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a spray bottle sitting on top on a table with a beautiful orange yellow sunset where the clouds are brightly lit from the sunset and a field is in the background slightly blurry",
]
COSMETIC_OUTPUT_DIRECTORY = "./output-claid-ai/cosmetic/"
if not os.path.exists(COSMETIC_OUTPUT_DIRECTORY):
os.makedirs(COSMETIC_OUTPUT_DIRECTORY)
iterate_over(image_urls=COSMETIC_IMAGE_URLS, prompts=COSMETIC_PROMPTS, file_names=list(map(str, range(1, len(COSMETIC_IMAGE_URLS) + 1))), result_directory=COSMETIC_OUTPUT_DIRECTORY)
# APPAREL
APPAREL_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F1.jpeg?alt=media&token=462bd079-f084-4a97-bdf5-51e1ea6454a3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F2.jpg?alt=media&token=7666a271-93c8-4fa5-bf46-e550f2832189",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F3.jpg?alt=media&token=3551ca21-e31a-4076-b810-1bc0aacbaceb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F4.jpg?alt=media&token=4a2d0c5d-b44a-479f-bc35-64fcc3d3d366",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F5.jpeg?alt=media&token=4624dafe-959b-4bfc-b230-7785780abcf7",
]
APPAREL_PROMPTS = [
"the image displays a jacket hanging on a wall standing against a baby blue background. The background is plain, textureless, doesn't have any discernible objects or patterns, and its color is baby blue",
"a baseball cap on a baseball field, with a bright sun in the background",
"a crocheted poncho on a fluffy blanket, with a soft green grass field in the background",
"the image displays a group of three people standing set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image illustrates a person walking set against a breathtaking mountain view. It exudes a professionalism in composition and performance.",
]
APPAREL_OUTPUT_DIRECTORY = "./output-claid-ai/apparel/"
if not os.path.exists(APPAREL_OUTPUT_DIRECTORY):
os.makedirs(APPAREL_OUTPUT_DIRECTORY)
iterate_over(image_urls=APPAREL_IMAGE_URLS, prompts=APPAREL_PROMPTS, file_names=list(map(str, range(1, len(APPAREL_IMAGE_URLS) + 1))), result_directory=APPAREL_OUTPUT_DIRECTORY)
# JEWELRY
JEWELRY_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F1.jpg?alt=media&token=0afec946-38cf-4773-a96a-d0c158358557",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F2.jpg?alt=media&token=9b93ee57-9343-4611-8156-76c512149002",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F3.jpg?alt=media&token=925a455c-1b58-469d-95c7-7db4ff5ac61e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F4.jpg?alt=media&token=c694560d-951d-4fe5-8390-a4c5df846f51",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F5.jpg?alt=media&token=38205d4d-ce4f-4168-9a91-94d872aed3fe",
]
JEWELRY_PROMPTS = [
"the image displays a ring with a pink stone on a cream marble countertop. The image features a minimalistic and professional looking background.",
"a long necklace on a black velvet cushion, with a cream stone wall in the background",
"the image displays a pair of earrings on a green marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a pair of wedding rings sitting next to each other on a concrete countertop. The image features a minimalistic and professional looking background.",
"the image displays a necklace in a cozy home. The image features a minimalistic and professional looking background.",
]
JEWELRY_OUTPUT_DIRECTORY = "./output-claid-ai/jewelry/"
if not os.path.exists(JEWELRY_OUTPUT_DIRECTORY):
os.makedirs(JEWELRY_OUTPUT_DIRECTORY)
iterate_over(image_urls=JEWELRY_IMAGE_URLS, prompts=JEWELRY_PROMPTS, file_names=list(map(str, range(1, len(JEWELRY_IMAGE_URLS) + 1))), result_directory=JEWELRY_OUTPUT_DIRECTORY)
# PEOPLE
PEOPLE_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F1.jpg?alt=media&token=5b57a70d-e94d-4056-8e48-2b8a2c296028",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F2.jpg?alt=media&token=f0e8a0bb-9fd7-4cc3-bd90-b5655321d46d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F3.jpg?alt=media&token=37ade83a-611e-4346-b4fe-5ee484f69ea3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F4.jpg?alt=media&token=3569a732-9be2-4b2d-b685-c55a1093fca8",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F5.jpg?alt=media&token=38875d9b-8f48-4bec-a30a-ca10be2b86d5",
]
PEOPLE_PROMPTS = [
"a person standing with their eyes closed on an old, twisted brick wall, with a grey field in the background",
"the image features a person walking on a boulder with a breathtaking mountain view in the background.",
"the image displays a person wearing glasses and a green shirt with New York in the background. The overall scenery in the background is typical and instantly transports you to New York",
"the image displays a person riding a skateboard set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image displays a person holding a suit case on a tropical beach on a bright day with a slightly blurred background of the ocean",
]
PEOPLE_OUTPUT_DIRECTORY = "./output-claid-ai/people/"
if not os.path.exists(PEOPLE_OUTPUT_DIRECTORY):
os.makedirs(PEOPLE_OUTPUT_DIRECTORY)
iterate_over(image_urls=PEOPLE_IMAGE_URLS, prompts=PEOPLE_PROMPTS, file_names=list(map(str, range(1, len(PEOPLE_IMAGE_URLS) + 1))), result_directory=PEOPLE_OUTPUT_DIRECTORY)
Please note that:
Phot.ai requires to make a first API call to start the processing, then make a second call to fetch the result. This code sets a delay of 300 seconds before fetching the result to maximize the chances of the result being ready.
Phot.ai doesn't support providing the seed of the random number generator, so you will not get exactly the same results than the ones shown above
import os
import requests
import time
import concurrent.futures
API_KEY = "YOUR_PHOT_AI_API_KEY"
def generate_background(input_image_url, prompt):
try:
url = "https://prodapi.phot.ai/external/api/v2/user_activity/background-generator"
payload = {
"file_name": "my-image.jpg",
"input_image_link": input_image_url,
"prompt": prompt
}
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
return data['order_id']
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def download_results(order_id, input_file_name, output_directory):
try:
url = f"https://prodapi.phot.ai/external/api/v1/user_activity/order-status?order_id={order_id}"
headers = {
"x-api-key": API_KEY,
}
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
for index, output_url in zip(range(1, 5), data['output_urls']):
response = requests.get(output_url)
response.raise_for_status() # To ensure the request was successful
variant_file_name = os.path.join(output_directory, f"phot-ai-{input_file_name}-variant_{index}.webp")
with open(variant_file_name, 'wb') as f:
f.write(response.content)
print(f"Image downloaded and saved to {variant_file_name}")
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def process_image(input_image_url, prompt, input_file_name, output_directory):
order_id = generate_background(input_image_url, prompt)
print(f"order_id: {order_id}")
time.sleep(300) # sleep while the results are generated
download_results(order_id, input_file_name, output_directory)
def iterate_over(image_urls, prompts, file_names, result_directory):
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
for image_url, prompt, file_name in zip(image_urls, prompts, file_names):
executor.submit(process_image, image_url, prompt, file_name, result_directory)
if __name__ == "__main__":
# FOOD
FOOD_IMAGES_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F1.jpg?alt=media&token=850ab5be-a503-40f1-a270-c7cdcc62bdeb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F2.png?alt=media&token=9c6e5512-efb8-47bc-b45d-01cb5b00b698",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F3.jpg?alt=media&token=04851dba-83bc-4d24-9549-ad029a838c33",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F4.jpeg?alt=media&token=191746c4-c528-4e2f-9e04-e1cac0b8d4b9",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F5.jpeg?alt=media&token=97421dcf-14b0-4353-913e-03428341e274",
]
FOOD_PROMPTS = [
"the image displays a plate of vegetables with succulents in the background. The image features a minimalistic and professional looking background.",
"a chocolate cupcake with blue frosting on a white marbled tray, with a pastel coloured table in the background",
"a plate of chicken wings and dipping sauces on a black scampered wooden table.",
"the image displays a piece of bread with avocado and greens on top bathed in a golden light. It has been captured professionally, emphasizing the warm tones and gleaming highlights.",
"the image displays a bowl with bread and vegetables foregrounded against a breathtaking mountain sunset. The object is set against a picturesque scene of a mountain during sunset.",
]
FOOD_OUTPUT_DIRECTORY = "./output-phot-ai/food/"
if not os.path.exists(FOOD_OUTPUT_DIRECTORY):
os.makedirs(FOOD_OUTPUT_DIRECTORY)
iterate_over(image_urls=FOOD_IMAGES_URLS, prompts=FOOD_PROMPTS, file_names=list(map(str, range(1, len(FOOD_IMAGES_URLS) + 1))), result_directory=FOOD_OUTPUT_DIRECTORY)
# COSMETIC
COSMETIC_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F1.jpeg?alt=media&token=837a3a2c-4621-44bc-84d7-ca1bafd7dad7",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F2.jpeg?alt=media&token=9327b3b6-68a6-4106-88cc-978afa5c048e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F3.png?alt=media&token=6c25d2aa-4a11-4b00-bac6-b98f59289b5c",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F4.jpg?alt=media&token=be6075e1-b754-4f98-8937-cba8d234942d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F5.jpg?alt=media&token=982083a1-b8df-40f7-88cc-c9185670f162",
]
COSMETIC_PROMPTS = [
"the image displays a bottle with a pink substance surrounded by cherry blossom. The image features a minimalistic and professional looking background.",
"the image displays a tube of false lashes in a bathroom. The image features a minimalistic and professional looking background.",
"the image displays an orange plastic bottle with a pump top on a tropical beach on a bright day with a slightly blurred background of the ocean",
"the image displays a tube of lotion on a cream marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a spray bottle sitting on top on a table with a beautiful orange yellow sunset where the clouds are brightly lit from the sunset and a field is in the background slightly blurry",
]
COSMETIC_OUTPUT_DIRECTORY = "./output-phot-ai/cosmetic/"
if not os.path.exists(COSMETIC_OUTPUT_DIRECTORY):
os.makedirs(COSMETIC_OUTPUT_DIRECTORY)
iterate_over(image_urls=COSMETIC_IMAGE_URLS, prompts=COSMETIC_PROMPTS, file_names=list(map(str, range(1, len(COSMETIC_IMAGE_URLS) + 1))), result_directory=COSMETIC_OUTPUT_DIRECTORY)
# APPAREL
APPAREL_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F1.jpeg?alt=media&token=462bd079-f084-4a97-bdf5-51e1ea6454a3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F2.jpg?alt=media&token=7666a271-93c8-4fa5-bf46-e550f2832189",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F3.jpg?alt=media&token=3551ca21-e31a-4076-b810-1bc0aacbaceb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F4.jpg?alt=media&token=4a2d0c5d-b44a-479f-bc35-64fcc3d3d366",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fapparel%2F5.jpeg?alt=media&token=4624dafe-959b-4bfc-b230-7785780abcf7",
]
APPAREL_PROMPTS = [
"the image displays a jacket hanging on a wall standing against a baby blue background. The background is plain, textureless, doesn't have any discernible objects or patterns, and its color is baby blue",
"a baseball cap on a baseball field, with a bright sun in the background",
"a crocheted poncho on a fluffy blanket, with a soft green grass field in the background",
"the image displays a group of three people standing set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image illustrates a person walking set against a breathtaking mountain view. It exudes a professionalism in composition and performance.",
]
APPAREL_OUTPUT_DIRECTORY = "./output-phot-ai/apparel/"
if not os.path.exists(APPAREL_OUTPUT_DIRECTORY):
os.makedirs(APPAREL_OUTPUT_DIRECTORY)
iterate_over(image_urls=APPAREL_IMAGE_URLS, prompts=APPAREL_PROMPTS, file_names=list(map(str, range(1, len(APPAREL_IMAGE_URLS) + 1))), result_directory=APPAREL_OUTPUT_DIRECTORY)
# JEWELRY
JEWELRY_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F1.jpg?alt=media&token=0afec946-38cf-4773-a96a-d0c158358557",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F2.jpg?alt=media&token=9b93ee57-9343-4611-8156-76c512149002",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F3.jpg?alt=media&token=925a455c-1b58-469d-95c7-7db4ff5ac61e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F4.jpg?alt=media&token=c694560d-951d-4fe5-8390-a4c5df846f51",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fjewelry%2F5.jpg?alt=media&token=38205d4d-ce4f-4168-9a91-94d872aed3fe",
]
JEWELRY_PROMPTS = [
"the image displays a ring with a pink stone on a cream marble countertop. The image features a minimalistic and professional looking background.",
"a long necklace on a black velvet cushion, with a cream stone wall in the background",
"the image displays a pair of earrings on a green marble countertop. The image features a minimalistic and professional looking background.",
"the image displays a pair of wedding rings sitting next to each other on a concrete countertop. The image features a minimalistic and professional looking background.",
"the image displays a necklace in a cozy home. The image features a minimalistic and professional looking background.",
]
JEWELRY_OUTPUT_DIRECTORY = "./output-phot-ai/jewelry/"
if not os.path.exists(JEWELRY_OUTPUT_DIRECTORY):
os.makedirs(JEWELRY_OUTPUT_DIRECTORY)
iterate_over(image_urls=JEWELRY_IMAGE_URLS, prompts=JEWELRY_PROMPTS, file_names=list(map(str, range(1, len(JEWELRY_IMAGE_URLS) + 1))), result_directory=JEWELRY_OUTPUT_DIRECTORY)
# PEOPLE
PEOPLE_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F1.jpg?alt=media&token=5b57a70d-e94d-4056-8e48-2b8a2c296028",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F2.jpg?alt=media&token=f0e8a0bb-9fd7-4cc3-bd90-b5655321d46d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F3.jpg?alt=media&token=37ade83a-611e-4346-b4fe-5ee484f69ea3",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F4.jpg?alt=media&token=3569a732-9be2-4b2d-b685-c55a1093fca8",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fpeople%2F5.jpg?alt=media&token=38875d9b-8f48-4bec-a30a-ca10be2b86d5",
]
PEOPLE_PROMPTS = [
"a person standing with their eyes closed on an old, twisted brick wall, with a grey field in the background",
"the image features a person walking on a boulder with a breathtaking mountain view in the background.",
"the image displays a person wearing glasses and a green shirt with New York in the background. The overall scenery in the background is typical and instantly transports you to New York",
"the image displays a person riding a skateboard set against an autumn-themed backdrop, captivating the essence of fall season.",
"the image displays a person holding a suit case on a tropical beach on a bright day with a slightly blurred background of the ocean",
]
PEOPLE_OUTPUT_DIRECTORY = "./output-phot-ai/people/"
if not os.path.exists(PEOPLE_OUTPUT_DIRECTORY):
os.makedirs(PEOPLE_OUTPUT_DIRECTORY)
iterate_over(image_urls=PEOPLE_IMAGE_URLS, prompts=PEOPLE_PROMPTS, file_names=list(map(str, range(1, len(PEOPLE_IMAGE_URLS) + 1))), result_directory=PEOPLE_OUTPUT_DIRECTORY)
import os
import requests
API_KEY = "YOUR_BRIA_API_KEY"
SEED = 117879368
def process_image(input_image_url, prompt, input_file_name, output_directory):
try:
url = "https://engine.prod.bria-api.com/v1/background/replace"
payload = {
"image_url": input_image_url,
"sync": True,
"bg_prompt": prompt,
"negative_prompt": "oversaturated, ugly, 3d, render, cartoon, grain, low-res, kitsch, text, lens, camera",
"refine_prompt": True,
"num_results": 4,
"seed": SEED
}
headers = {
"api_token": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers, timeout=300)
response.raise_for_status()
data = response.json()
for index, result in zip(range(1, 5), data['result']):
response = requests.get(result[0])
response.raise_for_status() # To ensure the request was successful
variant_file_name = os.path.join(output_directory, f"bria-ai-{input_file_name}-variant_{index}.png")
with open(variant_file_name, 'wb') as f:
f.write(response.content)
print(f"Image downloaded and saved to {variant_file_name}")
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)
def iterate_over(image_urls, prompts, file_names, result_directory):
for image_url, prompt, file_name in zip(image_urls, prompts, file_names):
process_image(image_url, prompt, file_name, result_directory)
if __name__ == "__main__":
# FOOD
FOOD_IMAGES_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F1.jpg?alt=media&token=850ab5be-a503-40f1-a270-c7cdcc62bdeb",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F2.png?alt=media&token=9c6e5512-efb8-47bc-b45d-01cb5b00b698",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F3.jpg?alt=media&token=04851dba-83bc-4d24-9549-ad029a838c33",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F4.jpeg?alt=media&token=191746c4-c528-4e2f-9e04-e1cac0b8d4b9",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Ffood%2F5.jpeg?alt=media&token=97421dcf-14b0-4353-913e-03428341e274",
]
FOOD_PROMPTS = [
"the image displays a plate of vegetables with succulents in the background. The image features a minimalistic and professional looking background.",
"a chocolate cupcake with blue frosting on a white marbled tray, with a pastel coloured table in the background",
"a plate of chicken wings and dipping sauces on a black scampered wooden table.",
"the image displays a piece of bread with avocado and greens on top bathed in a golden light. It has been captured professionally, emphasizing the warm tones and gleaming highlights.",
"the image displays a bowl with bread and vegetables foregrounded against a breathtaking mountain sunset. The object is set against a picturesque scene of a mountain during sunset.",
]
FOOD_OUTPUT_DIRECTORY = "./output-bria-ai/food/"
if not os.path.exists(FOOD_OUTPUT_DIRECTORY):
os.makedirs(FOOD_OUTPUT_DIRECTORY)
iterate_over(image_urls=FOOD_IMAGES_URLS, prompts=FOOD_PROMPTS, file_names=list(map(str, range(1, len(FOOD_IMAGES_URLS) + 1))), result_directory=FOOD_OUTPUT_DIRECTORY)
# COSMETIC
COSMETIC_IMAGE_URLS = [
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F1.jpeg?alt=media&token=837a3a2c-4621-44bc-84d7-ca1bafd7dad7",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F2.jpeg?alt=media&token=9327b3b6-68a6-4106-88cc-978afa5c048e",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F3.png?alt=media&token=6c25d2aa-4a11-4b00-bac6-b98f59289b5c",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F4.jpg?alt=media&token=be6075e1-b754-4f98-8937-cba8d234942d",
"https://firebasestorage.googleapis.com/v0/b/photoroom-demos.appspot.com/o/api-benchmark%2Fai-backgrounds%2Fcosmetic%2F5.jpg?alt=media&token=982083a1-b8df-40f7-88cc-c9185670f162",
]
COSMETIC_PROMPTS = [
"the image displays a bottle with a pink substance surrounded by cherry blossom. The image features a minimalistic and professional looking background.",
"the image displays a tube of false lashes in a bathroom. The image features a minimalistic and professional looking background.",
"the image displays an orange plastic bottle with a pump top on a tropical beach on a bright day with a slightly blurred background of the ocean",