File size: 1,614 Bytes
363c51a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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)