Spaces:
Running on Zero
Running on Zero
File size: 1,688 Bytes
31e9635 ae18889 31e9635 ae18889 31e9635 ae18889 | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import os
import base64
with open("style.css", "r", encoding="utf-8") as f:
CSS = f.read()
def load_template(filename: str) -> str:
filepath = os.path.join("templates", filename)
if os.path.exists(filepath):
with open(filepath, "r", encoding="utf-8") as f:
return f.read()
return ""
def get_file_b64(filename, mime_type):
search_paths = [
os.path.join("sample", filename),
os.path.join(".sample", filename),
os.path.join(".storage_lokal", "sample", filename),
os.path.join("/data", "sample", filename),
os.path.join("/data", filename)
]
for p in search_paths:
if os.path.exists(p):
try:
with open(p, "rb") as f:
data = base64.b64encode(f.read()).decode("utf-8")
return f"data:{mime_type};base64,{data}"
except Exception:
pass
return ""
def get_header_html() -> str:
top_bar = load_template("top_bar.html")
showcase = load_template("showcase.html")
b64_dict = {
"INPUT_WWW_B64": get_file_b64("input_www.jpg", "image/jpeg"),
"WWW_MP4_B64": get_file_b64("www.mp4", "video/mp4"),
"WWW_RIFE_X2_B64": get_file_b64("www-rife-x2.mp4", "video/mp4"),
"WWW_RIFE_X4_B64": get_file_b64("www-rife-x4.mp4", "video/mp4"),
"INPUT_XX_B64": get_file_b64("input_xx.jpg", "image/jpeg"),
"XX_MP4_B64": get_file_b64("xx.mp4", "video/mp4"),
"XX_RIFE_X2_B64": get_file_b64("xx-rife-x2.mp4", "video/mp4"),
}
for key, val in b64_dict.items():
showcase = showcase.replace(f"{{{key}}}", val)
return top_bar + showcase
|