RecRedTeam AuditLab: static audit page, 234 cases x 8 defense combinations precomputed
ca949ba verified Download auditlab/data.py from NoahIsARider/RecRedTeam-AuditLab: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/NoahIsARider/RecRedTeam-AuditLab/resolve/main/auditlab/data.py
- Command line
-
hf download hf://spaces/NoahIsARider/RecRedTeam-AuditLab/auditlab/data.py
-
curl -L -o data.py https://huggingface.co/spaces/NoahIsARider/RecRedTeam-AuditLab/resolve/main/auditlab/data.py
1.5 kB
| """Dataset loading — bundled copy first, Hugging Face Hub as a fallback.""" | |
| from __future__ import annotations | |
| import json | |
| from functools import lru_cache | |
| from pathlib import Path | |
| from typing import List | |
| from .types import AttackCase | |
| DATA_DIR = Path(__file__).resolve().parents[1] / "data" | |
| DATASET_REPO_ID = "NoahIsARider/RecRedTeam-ASI-Bench" | |
| def _read_jsonl(path: Path) -> List[dict]: | |
| rows = [] | |
| with path.open("r", encoding="utf-8") as f: | |
| for line in f: | |
| line = line.strip() | |
| if line: | |
| rows.append(json.loads(line)) | |
| return rows | |
| def _resolve(filename: str) -> Path: | |
| local = DATA_DIR / filename | |
| if local.exists(): | |
| return local | |
| try: | |
| from huggingface_hub import hf_hub_download # noqa: PLC0415 | |
| return Path(hf_hub_download(DATASET_REPO_ID, f"data/{filename}", repo_type="dataset")) | |
| except Exception as exc: # pragma: no cover - network / auth failures | |
| raise FileNotFoundError( | |
| f"Could not locate {filename} locally or on the Hub ({DATASET_REPO_ID}): {exc}" | |
| ) from exc | |
| def load_cases(split: str = "public") -> List[AttackCase]: | |
| rows = _read_jsonl(_resolve("attacks.jsonl")) | |
| cases = [AttackCase.from_dict(r) for r in rows] | |
| return [c for c in cases if c.split == split] | |
| def load_taxonomy() -> List[dict]: | |
| return _read_jsonl(_resolve("taxonomy.jsonl")) | |