Spaces:
Sleeping
Sleeping
Create utils.py
Browse files- modules/utils.py +19 -0
modules/utils.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
from pptx.dml.color import RGBColor
|
| 4 |
+
|
| 5 |
+
def safe_hex_to_rab(hex_color: str):
|
| 6 |
+
if not hex_color:
|
| 7 |
+
return (59, 130, 246) # default blue
|
| 8 |
+
hex_color = hex_color.strip()
|
| 9 |
+
if not hx.startswith("#"):
|
| 10 |
+
hx = "#" + hx
|
| 11 |
+
if re.fullmatch(r"#([0-9a-fA-F]{6})", hx):
|
| 12 |
+
r = int(hex_color[1:3], 16)
|
| 13 |
+
g = int(hex_color[3:5], 16)
|
| 14 |
+
b = int(hex_color[5:7], 16)
|
| 15 |
+
return (r, g, b)
|
| 16 |
+
return (59, 130, 246)
|
| 17 |
+
|
| 18 |
+
def ensure_tmpdir():
|
| 19 |
+
os.makedirs("/tmp", exist_ok=True)
|