""" push_to_hf.py Uploads the prepared model release directory to Hugging Face Model Hub. Prerequisites: 1. pip install huggingface_hub transformers 2. huggingface-cli login (or set HF_TOKEN environment variable) Usage: python push_to_hf.py --repo-id Rishabhkrw/unified-multilingual-ner-mdeberta """ import argparse import os from huggingface_hub import HfApi def main(): parser = argparse.ArgumentParser(description="Upload NER model to Hugging Face Hub") parser.add_argument("--repo-id", type=str, required=True, help="Hugging Face repository ID (e.g. username/model-name)") parser.add_argument("--private", action="store_true", help="Set repository to private") args = parser.parse_args() model_dir = os.path.dirname(os.path.abspath(__file__)) print(f"============================================================") print(f"Uploading model from: {model_dir}") print(f"Target HF Repository: {args.repo_id}") print(f"============================================================") api = HfApi() # Create repo if it doesn't exist repo_url = api.create_repo(repo_id=args.repo_id, private=args.private, exist_ok=True) print(f"Repository ready at: {repo_url}") # Upload folder contents (excluding script files) api.upload_folder( folder_path=model_dir, repo_id=args.repo_id, repo_type="model", ignore_patterns=["*.py", "*.sh"], ) print(f"\nSuccessfully published model to Hugging Face Hub!") print(f"Model URL: https://huggingface.co/{args.repo_id}") if __name__ == "__main__": main()