Spaces:
Running

File size: 3,358 Bytes
effcad2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2199bd7
effcad2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2199bd7
a2e1f78
effcad2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Upload this repo to a static Hugging Face Space (and optionally the split to a dataset repo).



    python scripts/upload.py --space <user>/foresightbench-rl --dry-run

    HF_TOKEN=... python scripts/upload.py --space <user>/foresightbench-rl \

        [--dataset <user>/foresightbench-rl-data]



The Space is the repo itself: README.md front matter (sdk: static) + index.html.

"""
from __future__ import annotations

import argparse
import os
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
IGNORE = [".cache/**", ".git/**", ".superpowers/**", ".pytest_cache/**", "**/__pycache__/**", "*.egg-info/**",
          "build/**", "tests/**", "POST.md", "**/spend.json", "spend.json", "**/judge_log.jsonl", "judge_log.jsonl",
          "**/samples*.jsonl", "samples*.jsonl", ".playwright-mcp/**"]


def _ignored(rel: str) -> bool:
    """Same decision the live upload makes (huggingface_hub applies IGNORE with fnmatch)."""
    from huggingface_hub.utils import filter_repo_objects
    return not list(filter_repo_objects([rel], ignore_patterns=IGNORE))


def space_files() -> list[str]:
    files = []
    for p in sorted(ROOT.rglob("*")):
        if p.is_file():
            rel = p.relative_to(ROOT).as_posix()
            if not _ignored(rel):
                files.append(rel)
    return files


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("--space", required=True, help="<user>/<name> of the static Space")
    ap.add_argument("--dataset", default=None, help="optional <user>/<name> dataset repo for data/*.jsonl")
    ap.add_argument("--dry-run", action="store_true")
    a = ap.parse_args()

    files = space_files()
    if a.dry_run:
        print(f"would upload {len(files)} files to space {a.space}:")
        print("\n".join(files))
        if a.dataset:
            print(f"would upload data/ to dataset {a.dataset}")
        return

    token = os.environ.get("HF_TOKEN")
    if not token:
        sys.exit("HF_TOKEN is not set")
    from huggingface_hub import HfApi
    api = HfApi(token=token)
    api.create_repo(a.space, repo_type="space", space_sdk="static", exist_ok=True)
    api.upload_folder(folder_path=str(ROOT), repo_id=a.space, repo_type="space",
                      ignore_patterns=IGNORE, delete_patterns=["build/**", "POST.md", "style.css"],
                      commit_message="ForesightBench RL environment + rollout browser")
    print(f"space: https://huggingface.co/spaces/{a.space}")
    if a.dataset:
        api.create_repo(a.dataset, repo_type="dataset", exist_ok=True)
        api.upload_folder(folder_path=str(ROOT / "foresightbench_env" / "data"), repo_id=a.dataset, repo_type="dataset",
                          path_in_repo="data", commit_message="RL splits")
        card = "\n".join([
            "---", "license: cc-by-4.0", "---", "# ForesightBench RL split", "",
            "Train = full 457-row corpus; eval = published 71-row eval (papers overlap). "
            f"Environment and docs: https://huggingface.co/spaces/{a.space}", ""])
        api.upload_file(path_or_fileobj=card.encode(), path_in_repo="README.md", repo_id=a.dataset, repo_type="dataset")
        print(f"dataset: https://huggingface.co/datasets/{a.dataset}")


if __name__ == "__main__":
    main()