from pathlib import Path import urllib import os def project_dir_path(root_dir:str): """Create project directories (data, artifacts, model) and return their paths.""" path_list = [os.path.join(root_dir, dir_) for dir_ in ["data", "artifacts", "model"]] for p in path_list: os.makedirs(p, exist_ok=True) return path_list def txt_file_downloader(url: str, data_dir: str, file_name: str) -> str: """Download a text file if missing and return its contents as a string.""" file_path = Path(data_dir).joinpath(file_name) if not file_path.is_file(): file_path.parent.mkdir(parents=True, exist_ok=True) urllib.request.urlretrieve(url=url, filename=file_path) return file_path.read_text(encoding="utf-8") ASSETS_DIR = Path(__file__).parent.parent / "assets" def load_css(): return (ASSETS_DIR / "css/theme.css").read_text(encoding="utf-8") def load_markdown(name): return (ASSETS_DIR / f"markdown/{name}.md").read_text(encoding="utf-8")