Spaces:
Paused
Paused
File size: 1,038 Bytes
f19488e 42ab630 f19488e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """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
|