Download src/utils.py from hoom4n/CharRNN: direct link, hf CLI and curl.
- Browser
- Download file 996 Bytes
-
https://huggingface.co/spaces/hoom4n/CharRNN/resolve/main/src/utils.py
- Command line
-
hf download hf://spaces/hoom4n/CharRNN/src/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/hoom4n/CharRNN/resolve/main/src/utils.py
996 Bytes
| 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") |