Spaces:
Sleeping
Sleeping
Download utils.py from walkingparadox/NLPforASD: direct link, hf CLI and curl.
- Browser
- Download file 711 Bytes
-
https://huggingface.co/spaces/walkingparadox/NLPforASD/resolve/main/utils.py
- Command line
-
hf download hf://spaces/walkingparadox/NLPforASD/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/walkingparadox/NLPforASD/resolve/main/utils.py
711 Bytes
| """Shared utility helpers.""" | |
| import json | |
| import os | |
| def load_json(path: str) -> dict | list: | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def save_json(data: dict | list, path: str) -> None: | |
| os.makedirs(os.path.dirname(path), exist_ok=True) | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |
| def file_exists(path: str) -> bool: | |
| return os.path.exists(path) | |
| def list_files(directory: str, extension: str = ".txt") -> list[str]: | |
| if not os.path.isdir(directory): | |
| return [] | |
| return [ | |
| os.path.join(directory, f) | |
| for f in os.listdir(directory) | |
| if f.endswith(extension) | |
| ] | |