Update app.py
Browse files
app.py
CHANGED
@@ -10,24 +10,35 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification, Auto
|
|
10 |
import os
|
11 |
import colorsys
|
12 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
class MPGPoster(Base):
|
14 |
@staticmethod
|
15 |
def create_color_shades(hex_color: str) -> colors.Color:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
"c100":
|
21 |
-
"
|
22 |
-
"
|
23 |
-
"
|
24 |
-
"c500": hex_color, # Base color
|
25 |
-
"c600": hex_color,
|
26 |
-
"c700": hex_color,
|
27 |
-
"c800": hex_color,
|
28 |
-
"c900": hex_color,
|
29 |
-
"c950": hex_color, # Darkest shade
|
30 |
}
|
|
|
|
|
|
|
31 |
return colors.Color(**shades)
|
32 |
|
33 |
def __init__(
|
|
|
10 |
import os
|
11 |
import colorsys
|
12 |
import time
|
13 |
+
def hex_to_rgb(hex_color: str) -> tuple[int, int, int]:
|
14 |
+
hex_color = hex_color.lstrip('#')
|
15 |
+
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
16 |
+
|
17 |
+
def rgb_to_hex(rgb_color: tuple[int, int, int]) -> str:
|
18 |
+
return "#{:02x}{:02x}{:02x}".format(*rgb_color)
|
19 |
+
|
20 |
+
def adjust_brightness(rgb_color: tuple[int, int, int], factor: float) -> tuple[int, int, int]:
|
21 |
+
# Convert RGB to HSV, adjust V (value), convert back to RGB
|
22 |
+
hsv_color = colorsys.rgb_to_hsv(*[v / 255.0 for v in rgb_color])
|
23 |
+
new_v = max(0, min(hsv_color[2] * factor, 1)) # Ensure the value is within [0, 1]
|
24 |
+
new_rgb = colorsys.hsv_to_rgb(hsv_color[0], hsv_color[1], new_v)
|
25 |
+
return tuple(int(v * 255) for v in new_rgb)
|
26 |
+
|
27 |
class MPGPoster(Base):
|
28 |
@staticmethod
|
29 |
def create_color_shades(hex_color: str) -> colors.Color:
|
30 |
+
base_rgb = hex_to_rgb(hex_color)
|
31 |
+
shades = {}
|
32 |
+
# Define brightness factors for shades
|
33 |
+
factors = {
|
34 |
+
"c50": 1.2, "c100": 1.1, "c200": 1.05,
|
35 |
+
"c300": 1.025, "c400": 1.0125, "c500": 1.0,
|
36 |
+
"c600": 0.9, "c700": 0.8, "c800": 0.7,
|
37 |
+
"c900": 0.6, "c950": 0.5
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
+
for shade, factor in factors.items():
|
40 |
+
new_rgb = adjust_brightness(base_rgb, factor)
|
41 |
+
shades[shade] = rgb_to_hex(new_rgb)
|
42 |
return colors.Color(**shades)
|
43 |
|
44 |
def __init__(
|