The `push_to_hub` method often requires a bit more complexity to handle repo creation, generate the model card and save weights.
A common approach is to save all of these files in a temporary folder, upload it and then delete it.  
```python
def push_to_hub(model: MyModelClass, repo_name: str) -> None:
api = HfApi()

# Create repo if not existing yet and get the associated repo_id
repo_id = api.create_repo(repo_name, exist_ok=True)

# Save all files in a temporary directory and push them in a single commit
with TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)

# Save weights
save_model(model, tmpdir / "model.safetensors")

# Generate model card
card = generate_model_card(model)
(tmpdir / "README.md").write_text(card)

# Save logs
# Save figures
# Save evaluation metrics
# ...

# Push to hub
return api.upload_folder(repo_id=repo_id, folder_path=tmpdir)
```  
This is of course only an example. If you are interested in more complex manipulations (delete remote files, upload
weights on the fly, persist weights locally, etc.) please refer to the [upload files](./upload) guide.