Update app.py
Browse files
app.py
CHANGED
|
@@ -8,22 +8,35 @@ from gradio.themes.utils import colors, fonts, sizes
|
|
| 8 |
import torch
|
| 9 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification, pipeline
|
| 10 |
import os
|
|
|
|
| 11 |
import time
|
| 12 |
|
| 13 |
-
# Helper function to convert hex to RGB tuple
|
| 14 |
def hex_to_rgb(hex_color: str) -> tuple[int, int, int]:
|
| 15 |
hex_color = hex_color.lstrip('#')
|
| 16 |
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
class MPGPoster(Base):
|
| 19 |
def __init__(
|
| 20 |
self,
|
| 21 |
*,
|
| 22 |
-
primary_hue: colors.Color | str =
|
| 23 |
-
background_hue: colors.Color | str =
|
| 24 |
-
secondary_dark_hue: colors.Color | str =
|
| 25 |
-
secondary_light_hue: colors.Color | str =
|
| 26 |
-
tertiary_highlight_hue: colors.Color | str =
|
| 27 |
spacing_size: sizes.Size | str = sizes.spacing_md,
|
| 28 |
radius_size: sizes.Size | str = sizes.radius_md,
|
| 29 |
text_size: sizes.Size | str = sizes.text_lg,
|
|
@@ -40,8 +53,8 @@ class MPGPoster(Base):
|
|
| 40 |
):
|
| 41 |
super().__init__(
|
| 42 |
primary_hue=primary_hue,
|
| 43 |
-
secondary_hue=secondary_dark_hue,
|
| 44 |
-
neutral_hue=background_hue,
|
| 45 |
spacing_size=spacing_size,
|
| 46 |
radius_size=radius_size,
|
| 47 |
text_size=text_size,
|
|
@@ -49,7 +62,6 @@ class MPGPoster(Base):
|
|
| 49 |
font_mono=font_mono,
|
| 50 |
)
|
| 51 |
|
| 52 |
-
# Using the theme in a Gradio interface
|
| 53 |
mpg_poster = MPGPoster()
|
| 54 |
|
| 55 |
auth_token = os.environ['HF_TOKEN']
|
|
|
|
| 8 |
import torch
|
| 9 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification, pipeline
|
| 10 |
import os
|
| 11 |
+
import colorsys
|
| 12 |
import time
|
| 13 |
|
|
|
|
| 14 |
def hex_to_rgb(hex_color: str) -> tuple[int, int, int]:
|
| 15 |
hex_color = hex_color.lstrip('#')
|
| 16 |
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
| 17 |
|
| 18 |
+
def generate_shades(base_color: str) -> colors.Color:
|
| 19 |
+
base_rgb = hex_to_rgb(base_color)
|
| 20 |
+
hsv = colorsys.rgb_to_hsv(*[v / 255.0 for v in base_rgb])
|
| 21 |
+
|
| 22 |
+
shades = []
|
| 23 |
+
for i in range(100, 1000, 100):
|
| 24 |
+
factor = i / 1000
|
| 25 |
+
new_v = hsv[2] * factor
|
| 26 |
+
rgb_shade = colorsys.hsv_to_rgb(hsv[0], hsv[1], new_v)
|
| 27 |
+
shades.append(tuple(int(v * 255) for v in rgb_shade))
|
| 28 |
+
|
| 29 |
+
return colors.Color(*shades)
|
| 30 |
+
|
| 31 |
class MPGPoster(Base):
|
| 32 |
def __init__(
|
| 33 |
self,
|
| 34 |
*,
|
| 35 |
+
primary_hue: colors.Color | str = generate_shades("#f47317"),
|
| 36 |
+
background_hue: colors.Color | str = generate_shades("#f6f6f6ff"),
|
| 37 |
+
secondary_dark_hue: colors.Color | str = generate_shades("#006c66"),
|
| 38 |
+
secondary_light_hue: colors.Color | str = generate_shades("#6ad5bc"),
|
| 39 |
+
tertiary_highlight_hue: colors.Color | str = generate_shades("#fbf22c"),
|
| 40 |
spacing_size: sizes.Size | str = sizes.spacing_md,
|
| 41 |
radius_size: sizes.Size | str = sizes.radius_md,
|
| 42 |
text_size: sizes.Size | str = sizes.text_lg,
|
|
|
|
| 53 |
):
|
| 54 |
super().__init__(
|
| 55 |
primary_hue=primary_hue,
|
| 56 |
+
secondary_hue=secondary_dark_hue,
|
| 57 |
+
neutral_hue=background_hue,
|
| 58 |
spacing_size=spacing_size,
|
| 59 |
radius_size=radius_size,
|
| 60 |
text_size=text_size,
|
|
|
|
| 62 |
font_mono=font_mono,
|
| 63 |
)
|
| 64 |
|
|
|
|
| 65 |
mpg_poster = MPGPoster()
|
| 66 |
|
| 67 |
auth_token = os.environ['HF_TOKEN']
|