"""Deploy the verified local checkpoint and code using local HF login credentials.""" import argparse import json from pathlib import Path from huggingface_hub import HfApi ROOT = Path(__file__).resolve().parent def deploy(repo_id): if not (ROOT / "model" / "model.safetensors").exists(): raise SystemExit("Run main.py to produce a trained model first.") if not (ROOT / "results" / "metrics.json").exists(): raise SystemExit("Missing evaluation results.") if not (ROOT / "model/onnx/model_quantized.onnx").exists(): raise SystemExit("Run export_onnx.py before deploying the Static Space.") api = HfApi() account = api.whoami()["name"] if repo_id.split("/")[0] != account: raise SystemExit( f"Signed in as {account}; repo must use this account namespace." ) api.create_repo( repo_id=repo_id, repo_type="space", space_sdk="static", private=False, exist_ok=True, ) # Explicit allowlist excludes credentials, environments, caches and raw data. api.upload_folder( repo_id=repo_id, repo_type="space", folder_path=str(ROOT), allow_patterns=[ "app.py", "main.py", "utils_data.py", "modeling_bert.py", "deploy.py", "verify.py", "export_onnx.py", "build_submission.py", "index.html", "static-app.js", "inference-worker.js", "README.md", "REPORT.md", "requirements*.txt", "dive-tuning.ipynb", "model/*", "model/onnx/*", "results/*.json", "results/*.txt", "results/*.jpg", "results/submission.csv", ], commit_message="Deploy H1 BERT fine-tuning code, trained checkpoint and evaluation", ) info = api.space_info(repo_id) deployment = { "repo_id": repo_id, "sdk": "static", "inference": "browser WASM / ONNX INT8", "space_url": f"https://huggingface.co/spaces/{repo_id}", "code_url": f"https://huggingface.co/spaces/{repo_id}/tree/main", "host": info.host, "revision": info.sha, } (ROOT / "deployment.json").write_text( json.dumps(deployment, indent=2), encoding="utf-8" ) print(json.dumps(deployment, indent=2)) if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--repo-id", default="cq111sto/h1-diving-tuning") deploy(parser.parse_args().repo_id)