File size: 1,316 Bytes
226b7bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Build the dashboard page (web/) and upload it to the Space, leaving data/ alone.

    python scripts/deploy_space.py

The page is static: it reads data/index.json and data/<family>.json, which the daily job
replaces. This only needs re-running when the page itself changes.
"""
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from huggingface_hub import CommitOperationAdd, CommitOperationDelete  # noqa: E402

from hfeco.hub import api  # noqa: E402

SPACE = "MiniMaxAI/oss-ecosystem"
KEEP = ("data/", "README.md", ".gitattributes")

subprocess.run(["npm", "run", "build"], cwd=ROOT / "web", check=True)
dist = ROOT / "web" / "dist"
files = [p for p in dist.rglob("*") if p.is_file() and not p.relative_to(dist).as_posix().startswith("data/")]
local = {p.relative_to(dist).as_posix() for p in files}
remote = set(api.list_repo_files(SPACE, repo_type="space"))
ops = [CommitOperationAdd(path_in_repo=p.relative_to(dist).as_posix(), path_or_fileobj=str(p)) for p in files]
ops += [CommitOperationDelete(path_in_repo=f) for f in sorted(remote - local) if not f.startswith(KEEP)]
api.create_commit(SPACE, ops, repo_type="space", commit_message="dashboard page")
print(f"uploaded {len(local)} files, removed {len(ops) - len(local)}")