Spaces:
Sleeping
Sleeping
File size: 677 Bytes
c9f5fa7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from pydantic import BaseModel
from PIL import Image
class ColorItem(BaseModel):
R: int
"The red component of the color."
G: int
"The green component of the color."
B: int
"The blue component of the color."
count: int
"The frequency of the color in the image."
class ColorPalette(BaseModel):
colors: list[ColorItem]
"""A list of colors and their frequency."""
def to_rgb(self):
return [(color.R, color.G, color.B) for color in self.colors]
def to_hex(self):
return [f"#{color.R:02x}{color.G:02x}{color.B:02x}" for color in self.colors]
def get_num_colors(self):
return len(self.colors)
|