Spaces:
Sleeping
Sleeping
| import os | |
| from huggingface_hub import HfApi | |
| # Info to change for your repository | |
| # ---------------------------------- | |
| TOKEN = os.environ.get("HF_TOKEN") # A read/write token for your org | |
| OWNER = "searchagent_leaderboard" | |
| REPO_ID = f"{OWNER}/leaderboard" | |
| QUEUE_REPO = f"{OWNER}/requests" | |
| RESULTS_REPO = f"{OWNER}/results" | |
| # Resolve project root (two levels up from this file when packaged) | |
| _SRC_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| _PROJECT_ROOT = os.path.abspath(os.path.join(_SRC_DIR, os.pardir)) | |
| def _resolve_cache_path() -> str: | |
| """Determine where eval assets should be read from.""" | |
| # Highest priority: explicit environment override | |
| env_override = os.getenv("EVAL_CACHE_PATH") | |
| if env_override: | |
| return os.path.abspath(env_override) | |
| # Next: if HF_HOME contains the expected folders, use it | |
| hf_home = os.getenv("HF_HOME") | |
| if hf_home: | |
| hf_home = os.path.abspath(hf_home) | |
| expected_results = os.path.join(hf_home, "eval-results") | |
| expected_queue = os.path.join(hf_home, "eval-queue") | |
| if os.path.isdir(expected_results) or os.path.isdir(expected_queue): | |
| return hf_home | |
| # Fallback to project root so bundled demo data is found | |
| return _PROJECT_ROOT | |
| CACHE_PATH = _resolve_cache_path() | |
| def _debug_path(label: str, path: str, max_entries: int = 10) -> None: | |
| try: | |
| entries = os.listdir(path) | |
| preview = entries[:max_entries] | |
| print(f"[envs] {label}: {path} | {len(entries)} entries | preview={preview}") | |
| except FileNotFoundError: | |
| print(f"[envs] {label}: {path} | missing") | |
| except Exception as exc: | |
| print(f"[envs] {label}: {path} | error={exc}") | |
| # Local caches | |
| EVAL_REQUESTS_PATH = os.path.join(CACHE_PATH, "eval-queue") | |
| EVAL_RESULTS_PATH = os.path.join(CACHE_PATH, "eval-results") | |
| EVAL_REQUESTS_PATH_BACKEND = os.path.join(CACHE_PATH, "eval-queue-bk") | |
| EVAL_RESULTS_PATH_BACKEND = os.path.join(CACHE_PATH, "eval-results-bk") | |
| if os.getenv("DEBUG_ENV_PATHS", "0").lower() in {"1", "true", "yes"}: | |
| print( | |
| f"[envs] HF_HOME={os.getenv('HF_HOME')} | EVAL_CACHE_PATH={os.getenv('EVAL_CACHE_PATH')} | CACHE_PATH={CACHE_PATH}" | |
| ) | |
| _debug_path("EVAL_RESULTS_PATH", EVAL_RESULTS_PATH) | |
| _debug_path("EVAL_REQUESTS_PATH", EVAL_REQUESTS_PATH) | |
| API = HfApi(token=TOKEN) | |