Skip to content

Instantly share code, notes, and snippets.

@peterc
Created August 2, 2025 16:25
Show Gist options
  • Save peterc/781117215a8c608ba056afecf3120142 to your computer and use it in GitHub Desktop.
Save peterc/781117215a8c608ba056afecf3120142 to your computer and use it in GitHub Desktop.
Generate color palettes by generating AI images and extracting the colors
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')
@peterc
Copy link
Author

peterc commented Aug 2, 2025

Screenshot 2025-08-02 at 17 27 00

@peterc
Copy link
Author

peterc commented Aug 2, 2025

image

@peterc
Copy link
Author

peterc commented Aug 2, 2025

image

@peterc
Copy link
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