code2lora-gru-demo / tools /publish.py
code2lora's picture
Update app
7bacdbf verified
Raw History Blame Contribute Delete
1.47 kB
#!/usr/bin/env python3
"""Push the app and a built data directory to the Space, replacing old data.
python hf_space_demo/tools/publish.py --data-dir hf_space_demo/data [--public]
"""
from __future__ import annotations
import argparse
from pathlib import Path
from huggingface_hub import HfApi
HERE = Path(__file__).resolve().parents[1]
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--data-dir", required=True)
ap.add_argument("--space", default="code2lora/code2lora-gru-demo")
ap.add_argument("--public", action="store_true")
args = ap.parse_args()
data = Path(args.data_dir)
if not (data / "index.json").exists():
raise SystemExit(f"{data}/index.json not found; run build_space_data.py first")
api = HfApi()
api.upload_folder(repo_id=args.space, repo_type="space", folder_path=str(HERE),
ignore_patterns=["data/*", "**/__pycache__/*", "*.pyc"],
commit_message="Update app")
api.upload_folder(repo_id=args.space, repo_type="space", folder_path=str(data),
path_in_repo="data", delete_patterns=["*"],
commit_message="Precomputed GRU states and cached predictions")
if args.public:
api.update_repo_settings(args.space, repo_type="space", private=False)
print(f"https://huggingface.co/spaces/{args.space}", api.get_space_runtime(args.space).stage)
if __name__ == "__main__":
main()