Spaces:
Running
Running
Download scripts/upload.py from ruhzi/foresightbench-rl: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/spaces/ruhzi/foresightbench-rl/resolve/main/scripts/upload.py
- Command line
-
hf download hf://spaces/ruhzi/foresightbench-rl/scripts/upload.py
-
curl -L -o upload.py https://huggingface.co/spaces/ruhzi/foresightbench-rl/resolve/main/scripts/upload.py
3.36 kB
| """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() | |