in models/vision_language_model.py [0:0]
def push_to_hub(self, repo_id: str, private: bool = False) -> None:
"""
Push the model and configuration to the Hugging Face Hub.
Args:
repo_id (str): The repo ID on the Hugging Face Hub.
"""
from huggingface_hub import create_repo, upload_folder
# Create repo
repo_url = create_repo(repo_id=repo_id, private=private, exist_ok=True)
repo_id = repo_url.repo_id
print("Created repo: ", repo_url)
with tempfile.TemporaryDirectory() as save_path:
# Save to tmp directory
self.save_pretrained(save_path)
# Save model card
with open(os.path.join(save_path, "README.md"), "w") as f:
f.write(MODEL_CARD_TEMPLATE.format(repo_id=repo_id))
# Upload
return upload_folder(
repo_id=repo_id,
repo_type="model",
folder_path=save_path,
commit_message="Upload nanoVLM using push_to_hub",
)