Spaces:
Sleeping
Sleeping
Download tasks/database.py from Maheswar01/my-env: direct link, hf CLI and curl.
- Browser
- Download file 665 Bytes
-
https://huggingface.co/spaces/Maheswar01/my-env/resolve/main/tasks/database.py
- Command line
-
hf download hf://spaces/Maheswar01/my-env/tasks/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Maheswar01/my-env/resolve/main/tasks/database.py
665 Bytes
| """Scenario row loading from the local JSON dataset (no live DB).""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| def _dataset_path(data_path: Path | None = None) -> Path: | |
| if data_path is not None: | |
| return data_path | |
| return Path(__file__).resolve().parent.parent / "data" / "scam_dataset.json" | |
| def load_scenario_by_id(scenario_id: str, data_path: Path | None = None) -> dict: | |
| path = _dataset_path(data_path) | |
| for row in json.loads(path.read_text(encoding="utf-8")): | |
| if row["id"] == scenario_id: | |
| return row | |
| raise KeyError(scenario_id) | |
| __all__ = ["load_scenario_by_id", "_dataset_path"] | |