Created
August 2, 2025 16:25
-
-
Save peterc/781117215a8c608ba056afecf3120142 to your computer and use it in GitHub Desktop.
Generate color palettes by generating AI images and extracting the colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import replicate | |
from Pylette import extract_colors | |
# YOU NEED A REPLICATE API TOKEN IN 'REPLICATE_API_TOKEN' | |
prompt = sys.argv[1] if len(sys.argv) > 1 else "sandy beach" | |
output = replicate.run( | |
"black-forest-labs/flux-krea-dev", | |
input={ | |
"prompt": prompt, | |
"guidance": 3, | |
"output_quality": 95, | |
"megapixels": "1", | |
"output_format": "jpg", | |
"num_inference_steps": 30, | |
"disable_safety_checker": True | |
} | |
) | |
url = output[0] | |
response = requests.get(url) | |
if response.status_code == 200: | |
with open("output_image.jpg", "wb") as f: | |
f.write(response.content) | |
else: | |
print(f"Failed to retrieve image: {response.status_code}") | |
exit(1) | |
palette = extract_colors(image='output_image.jpg', palette_size=10) | |
palette.display(save_to_file=True) | |
#palette.save(filename='output_image_palette', extension='png') |
Author
peterc
commented
Aug 2, 2025

OK, so you get the idea!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment