File size: 2,720 Bytes
d165865 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/usr/bin/env python3
"""
Push zindango-slm to Hugging Face Hub.
Usage:
python scripts/push_to_hub.py [--model-dir PATH] [--repo-id USERNAME/zindango-slm]
Requires: huggingface-cli login (or HF_TOKEN env)
"""
import argparse
from pathlib import Path
from huggingface_hub import HfApi, create_repo, upload_folder
def main():
parser = argparse.ArgumentParser(description="Push zindango-slm to Hugging Face Hub")
parser.add_argument(
"--model-dir",
type=str,
default="outputs/zindango-slm-20260215_124754",
help="Local model directory to upload",
)
parser.add_argument(
"--repo-id",
type=str,
default=None,
help="Hub repo ID (username/zindango-slm). Default: infer from login",
)
parser.add_argument(
"--private",
action="store_true",
help="Create private repository",
)
parser.add_argument(
"--skip-create",
action="store_true",
help="Skip create_repo (use if repo already exists or create manually at https://huggingface.co/new)",
)
args = parser.parse_args()
model_dir = Path(args.model_dir)
if not model_dir.exists():
raise SystemExit(f"Model directory not found: {model_dir}")
api = HfApi()
try:
user = api.whoami()
username = user["name"]
except Exception as e:
raise SystemExit(
f"Not logged in to Hugging Face. Run: huggingface-cli login\nError: {e}"
)
repo_id = args.repo_id or f"{username}/zindango-slm"
print(f"Uploading to https://huggingface.co/{repo_id}")
# Create repo if needed (skip if --skip-create or 403)
if not args.skip_create:
try:
create_repo(repo_id, repo_type="model", private=args.private, exist_ok=True)
except Exception as e:
err = str(e).lower()
if "403" in err or "forbidden" in err or "rights" in err:
print("Note: Could not create repo (check token write access).")
print("Create it manually at: https://huggingface.co/new")
print("Then run with: --skip-create")
raise
if "already exists" not in err and "409" not in err:
raise
# Exclude checkpoint subdir and training artifacts
ignore_patterns = ["checkpoint-*", "training_args.bin", "*.pt", ".git*"]
upload_folder(
folder_path=str(model_dir),
repo_id=repo_id,
repo_type="model",
ignore_patterns=ignore_patterns,
commit_message="Upload zindango-slm: SFT for Zindango (English-only)",
)
print(f"Done. Model: https://huggingface.co/{repo_id}")
if __name__ == "__main__":
main()
|