mx / scripts /push_hf.py
Ethscriptions's picture
Step 1: 项目计划与分镜大纲 README
363c51a verified
Raw History Blame Contribute Delete
1.61 kB
"""Push project progress to HF Space Ethscriptions/mx.
Usage: HF_TOKEN=... python3 scripts/push_hf.py "commit message"
Uploads README.md, frontend/src -> src/, frontend/public/audio -> audio/, and built static site (dist_static) at root.
"""
import os, sys
from huggingface_hub import HfApi, CommitOperationAdd
REPO = "Ethscriptions/mx"
api = HfApi(token=os.environ["HF_TOKEN"])
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
msg = sys.argv[1] if len(sys.argv) > 1 else "update"
ops = []
def add_dir(local, remote_prefix):
if not os.path.isdir(local):
return
for dp, _, files in os.walk(local):
for f in files:
lp = os.path.join(dp, f)
rel = os.path.relpath(lp, local).replace(os.sep, "/")
ops.append(CommitOperationAdd(path_in_repo=f"{remote_prefix}{rel}", path_or_fileobj=lp))
ops.append(CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=os.path.join(root, "README.md")))
add_dir(os.path.join(root, "frontend", "src"), "src/")
add_dir(os.path.join(root, "scripts"), "scripts/")
static = os.path.join(root, "dist_static")
if os.path.isdir(static):
add_dir(static, "") # includes index.html, assets/, audio/
else:
add_dir(os.path.join(root, "frontend", "public", "audio"), "audio/")
placeholder = os.path.join(root, "scripts", "placeholder.html")
if os.path.exists(placeholder):
ops.append(CommitOperationAdd(path_in_repo="index.html", path_or_fileobj=placeholder))
api.create_commit(repo_id=REPO, repo_type="space", operations=ops, commit_message=msg)
print("pushed", len(ops), "files:", msg)