""" Push Bhaari AI artifacts to HuggingFace Hub """ import os from pathlib import Path from huggingface_hub import HfApi, login from datetime import datetime def push_to_huggingface( folder_path: str, repo_id: str = "mohit-vashishta/bhaari-tok-v1", commit_message: str = None, token: str = None ): """ Push folder to HuggingFace Hub Args: folder_path: Path to folder to upload repo_id: HuggingFace repo ID commit_message: Commit message token: HF token (or set HF_TOKEN env var) """ token = token or os.environ.get("HF_TOKEN") if not token: raise ValueError("HF_TOKEN not set. Set it as environment variable or pass as argument.") # Login login(token=token) # Initialize API api = HfApi() # Create repo if not exists try: api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True) print(f"Repo created/exists: {repo_id}") except Exception as e: print(f"Repo creation note: {e}") # Upload folder if commit_message is None: commit_message = f"Update {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" print(f"Uploading {folder_path} to {repo_id}...") api.upload_folder( folder_path=folder_path, repo_id=repo_id, commit_message=commit_message ) print(f"Successfully uploaded to: https://huggingface.co/{repo_id}") return f"https://huggingface.co/{repo_id}" def push_checkpoint( checkpoint_path: str, phase: str, step: int, loss: float, token: str = None ): """Push training checkpoint to HuggingFace""" repo_id = f"mohit-vashishta/bhaari-ai-{phase}" commit_message = f"Checkpoint {phase} step {step}, loss: {loss:.4f}" return push_to_huggingface( folder_path=checkpoint_path, repo_id=repo_id, commit_message=commit_message, token=token ) def push_report( report_path: str, phase: str, token: str = None ): """Push training report to HuggingFace""" repo_id = f"mohit-vashishta/bhaari-ai-reports" commit_message = f"Report: {phase} - {datetime.now().strftime('%Y-%m-%d')}" return push_to_huggingface( folder_path=str(Path(report_path).parent), repo_id=repo_id, commit_message=commit_message, token=token ) if __name__ == "__main__": import sys if len(sys.argv) < 2: print("Usage: python push_to_hf.py [repo_id]") sys.exit(1) folder = sys.argv[1] repo = sys.argv[2] if len(sys.argv) > 2 else "mohit-vashishta/bhaari-tok-v1" push_to_huggingface(folder, repo)