Skip to content

Commit

Permalink
Replace deprecated huggingface_hub.Repository by HfApi (#465)
Browse files Browse the repository at this point in the history
* Commits from #462

* update ci

* `hf_hub_download` -> `snapshot_download`

* fix local dir; handle lfs for mp4

* rm line

---------

Co-authored-by: Quentin Gallouédec <[email protected]>
Co-authored-by: Antonin RAFFIN <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2024
1 parent 9846160 commit 726e2f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### New Features

### Bug fixes
- Replaced deprecated `huggingface_hub.Repository` when pushing to Hugging Face Hub by the recommended `HfApi` (see https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http) (@cochaviz)

### Documentation

Expand Down
14 changes: 8 additions & 6 deletions rl_zoo3/push_to_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ def package_to_hub(
private=False,
exist_ok=True,
)

# Git pull
# Retrieve current repo state
repo_local_path = Path(local_repo_path) / repo_name
repo = Repository(repo_local_path, clone_from=repo_url)
repo.git_pull(rebase=True)
api.snapshot_download(repo_id=repo_id, local_dir=repo_local_path)

repo.lfs_track(["*.mp4"])
# Add mp4 files to .gitattributes
with open(repo_local_path / ".gitattributes", "a+") as f:
f.seek(0) # Move the file pointer to the beginning of the file
if not any("*.mp4" in line for line in f):
f.write("*.mp4 filter=lfs diff=lfs merge=lfs -text\n")

# Step 1: Save the model
print("Saving model to:", repo_local_path / model_name)
Expand Down Expand Up @@ -269,7 +271,7 @@ def package_to_hub(
save_model_card(repo_local_path, generated_model_card, metadata)

msg.info(f"Pushing repo {repo_name} to the Hugging Face Hub")
repo.push_to_hub(commit_message=commit_message)
api.upload_folder(repo_id=repo_id, folder_path=repo_local_path, commit_message=commit_message)

msg.info(f"Your model is pushed to the hub. You can view your model here: {repo_url}")
return repo_url
Expand Down

0 comments on commit 726e2f1

Please sign in to comment.