Links

Image python snippets

Snippets to get up and running

Simple snippet to colorize one image with defaults

import requests
# 1. Change the base url
# 2. Add your API Key
url = "https://apis.palette.fm/105esxukgwqbp7g4/colorize_image_with_auto_prompt"
files = {'image': ('black_and_white.jpg', open(' ./black_and_white.jpg', 'rb'), 'image/jpeg' )}
headers = {"X-BLOBR-KEY": ""}
response = requests.post(url, files=files, headers=headers)
f = open( 'colorized_image.jpg', 'wb' )
f.write(response.content)
f.close()

Same snippet with the defaults explained and shown

import requests
url = "https://apis.palette.fm/105esxukgwqbp7g4/colorize_image_with_auto_prompt"
files = {
'image': ('black_and_white.jpg', open(' ./black_and_white.jpg', 'rb'), 'image/jpeg' )
}
data = {
"resolution": "watermarked-sd", # watermarked-sd, sd, full-hd, or 4k
"prompt": "", # replace with custom prompt
"standard_filter_id": "1", # 1-20 default filters
"artistic_filter_id": "O", # 1-100 more creative filters
"raw_captions": "false", # true or false, remove post and prefix from promot
"pre_fix": "", # create your own pre_fix, e.g. A photo of
"post_fix": "", # create your own pre_fix, e.g. HDR and colorful.
"auto_color": "true", # true or false, color balancing
"white_balance": "false", # white balancing
"temperature": "-0.1", # 0.0 - 1.0, cold or warm filter
"saturation": "1.1" # 0.0 - 2.0, adjust saturation
}
headers = {
"X-BLOBR-KEY": ""
}
response = requests.post(url, files=files, data=data, headers=headers)
f = open( 'colorized_image.jpg', 'wb' )
f.write(response.content)
f.close()

Automatically colorize one image and return it in a Base64 string and print the caption

import requests
import base64
url = "https://apis.palette.fm/105esxukgwqbp7g4/colorize_image_with_auto_prompt_base64"
files = {
'image': ('black_and_white.jpg', open(' ./black_and_white.jpg', 'rb'), 'image/jpeg' )
}
data = {
"resolution": "watermarked-sd", # watermarked-sd, sd, full-hd, or 4k
"prompt": "", # replace with custom prompt
"standard_filter_id": "1", # 1-20 default filters
"artistic_filter_id": "O", # 1-100 more creative filters
"raw_captions": "false", # true or false, remove post and prefix from promot
"pre_fix": "", # create your own pre_fix, e.g. A photo of
"post fix": "", # create your own pre_fix, e.g. HDR and colorful.
"auto_color": "true", # true or false, color balancing
"white_balance": "false", # white balancing
"temperature": "-0.1", # 0.0 - 1.0, cold or warm filter
"saturation": "1.1" # 0.0 - 2.0, adjust saturation
}
headers = {
"X-BLOBR-KEY": ""
}
response = requests .post(url, files=files, data=data, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Get the response content in JSON format
response_json = response.json()
# Extract the image and caption values
image_base64 = response_json["image"]
caption = response_json["caption"]
# Save the image into a file
with open("colorized_image.jpg", "wb") as f:
f.write(base64.b64decode(image_base64))
# Print the caption
print(caption)
else:
print(f"Request failed with status code: {response.status_code}")

Use a folder of reference images to colorize one image

import os
import time
import requests
from PIL import Image
FOLDER_PATH = "test_images" # Replace with the path to your folder
URL = "https://apis.palette.fm/j8m19inzwtaij4w6/colorize_image_with_reference_image"
HEADERS = {"X-BLOBR-KEY": ""}
def main():
i = 0
for filename in os.listdir(FOLDER_PATH):
if filename.endswith((".jpg", ".jpeg", ".png")):
process_image(filename)
i += 1
time.sleep(0.5)
def process_image(filename):
image_path = os.path.join(FOLDER_PATH, filename)
files = {
'image': ('black_and_white.jpeg', open('./black_and_white.jpeg', 'rb'), 'image/jpeg'),
'image_ref': (filename, open(image_path, 'rb'), 'image/jpeg')
}
data = {
"resolution": "4k",
"auto_color": "false",
"white_balance": "false",
"temperature": "0.0",
"saturation": "1.2"
}
response = requests.post(URL, files=files, data=data, headers=HEADERS)
save_response_content(response, 'colorized_' + filename)
def save_response_content(response, output_filename):
with open(output_filename, 'wb') as f:
f.write(response.content)
if __name__ == "__main__":
main()

Colorize several BW frames with one reference image

import os
import time
import requests
from PIL import Image
# Folder Paths
REFERENCE_IMAGE_FOLDER = "reference_image_folder"
BW_IMAGES_FOLDER = "bw_images_folder"
OUTPUT_FOLDER = "output_folder"
URL = "https://apis.palette.fm/j8m19inzwtaij4w6/colorize_image_with_reference_image"
HEADERS = {"X-BLOBR-KEY": ""}
def main():
i = 0
reference_image_path = get_reference_image_path()
for filename in os.listdir(BW_IMAGES_FOLDER):
if filename.endswith((".jpg", ".jpeg", ".png")):
process_image(filename, reference_image_path)
i += 1
time.sleep(0.5)
def get_reference_image_path():
for filename in os.listdir(REFERENCE_IMAGE_FOLDER):
if filename.endswith((".jpg", ".jpeg", ".png")):
return os.path.join(REFERENCE_IMAGE_FOLDER, filename)
return None
def process_image(filename, reference_image_path):
bw_image_path = os.path.join(BW_IMAGES_FOLDER, filename)
output_image_path = os.path.join(OUTPUT_FOLDER, 'colorized_' + filename)
files = {
'image': (filename, open(bw_image_path, 'rb'), 'image/jpeg'),
'image_ref': ('reference.jpg', open(reference_image_path, 'rb'), 'image/jpeg')
}
data = {
"resolution": "4k",
"auto_color": "false",
"white_balance": "false",
"temperature": "0.0",
"saturation": "1.2"
}
response = requests.post(URL, files=files, data=data, headers=HEADERS)
save_response_content(response, output_image_path)
def save_response_content(response, output_filename):
with open(output_filename, 'wb') as f:
f.write(response.content)
if __name__ == "__main__":
main()

Generate 20 Prompts

import requests
import json
# Note: replace jpwfm2z1g587733t with your link (see your portal)
url = "https://apis.palette.fm/jpwfm2z1g587733t/generate_image_prompt"
files = {
'image': ('test.jpg', open('./test.jpg', 'rb'), 'image/jpeg')
}
data = {
"standard_filter_id": "0", # 1-20, 0 is disabled
"artistic_filter_id": "0", # 1-100, 0 is disabled
"all_standard_filters": "true", # return all 20 prompts
"all_artistic_filters": "false", # return all 100 prompts
"raw_captions": "false" # remove pre and post fix to the caption
}
# Note: Add your api key
headers = {
"X-BLOBR-KEY": ""
}
response = requests.post(url, files=files, data=data, headers=headers)
prompts = data = json.loads(response.text)