Download src/triage_llm/utils.py from perachon/p14-space: direct link, hf CLI and curl.
- Browser
- Download file 961 Bytes
-
https://huggingface.co/spaces/perachon/p14-space/resolve/main/src/triage_llm/utils.py
- Command line
-
hf download hf://spaces/perachon/p14-space/src/triage_llm/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/perachon/p14-space/resolve/main/src/triage_llm/utils.py
961 Bytes
| from __future__ import annotations | |
| import json | |
| import os | |
| from pathlib import Path | |
| from typing import Any | |
| def ensure_dir(path: str | Path) -> Path: | |
| p = Path(path) | |
| p.mkdir(parents=True, exist_ok=True) | |
| return p | |
| def read_jsonl(path: str | Path) -> list[dict[str, Any]]: | |
| rows: list[dict[str, Any]] = [] | |
| with open(path, encoding="utf-8") as f: | |
| for line in f: | |
| line = line.strip() | |
| if not line: | |
| continue | |
| rows.append(json.loads(line)) | |
| return rows | |
| def write_jsonl(path: str | Path, rows: list[dict[str, Any]]) -> None: | |
| ensure_dir(Path(path).parent) | |
| with open(path, "w", encoding="utf-8") as f: | |
| for row in rows: | |
| f.write(json.dumps(row, ensure_ascii=False) + "\n") | |
| def getenv_bool(name: str, default: bool = False) -> bool: | |
| v = os.getenv(name) | |
| if v is None: | |
| return default | |
| return v.strip().lower() in {"1", "true", "yes", "y", "on"} | |