Skip to content

Commit 726e2f1

Browse files
qgallouedecaraffin
andauthored
Replace deprecated huggingface_hub.Repository by HfApi (#465)
* 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]>
1 parent 9846160 commit 726e2f1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### New Features
88

99
### Bug fixes
10+
- 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)
1011

1112
### Documentation
1213

rl_zoo3/push_to_hub.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,15 @@ def package_to_hub(
195195
private=False,
196196
exist_ok=True,
197197
)
198-
199-
# Git pull
198+
# Retrieve current repo state
200199
repo_local_path = Path(local_repo_path) / repo_name
201-
repo = Repository(repo_local_path, clone_from=repo_url)
202-
repo.git_pull(rebase=True)
200+
api.snapshot_download(repo_id=repo_id, local_dir=repo_local_path)
203201

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

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

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

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

0 commit comments

Comments
 (0)