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