Spaces:
Paused
Paused
Download progress.py from Effina-byte/Agent-test: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/Effina-byte/Agent-test/resolve/main/progress.py
- Command line
-
hf download hf://spaces/Effina-byte/Agent-test/progress.py
-
curl -L -o progress.py https://huggingface.co/spaces/Effina-byte/Agent-test/resolve/main/progress.py
1.04 kB
| """Tiny on-disk store of solved answers, so a run can resume. | |
| Every successfully solved question is saved here immediately; the next run skips those and only | |
| retries the ones that failed. Delete progress.json (or use the "Clear saved | |
| progress" button) to start over. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import os | |
| from pathlib import Path | |
| PROGRESS_FILE = Path(os.getenv("PROGRESS_FILE", "progress.json")) | |
| def is_error(answer: str | None) -> bool: | |
| return not answer or str(answer).startswith("AGENT_ERROR") | |
| def load() -> dict[str, str]: | |
| try: | |
| return json.loads(PROGRESS_FILE.read_text(encoding="utf-8")) | |
| except Exception: | |
| return {} | |
| def save_answer(task_id: str, answer: str) -> None: | |
| if is_error(answer): | |
| return | |
| data = load() | |
| data[str(task_id)] = answer | |
| PROGRESS_FILE.write_text( | |
| json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8" | |
| ) | |
| def clear() -> None: | |
| try: | |
| PROGRESS_FILE.unlink() | |
| except FileNotFoundError: | |
| pass | |