Commiting and pushing workaround

#15
by juan-all-hands - opened
OpenHands org

Commit/Push to main (via API):

Download the file from HF using hf_hub_download()
Modify the file locally
Use create_commit() from huggingface_hub with CommitOperationAdd to push directly to the repo
from huggingface_hub import hf_hub_download, create_commit, CommitOperationAdd

Download

path = hf_hub_download("OpenHands/openhands-index", "file.py", repo_type="space")

Modify locally...

Push

create_commit(
token=token, # HF token
repo_id="OpenHands/openhands-index",
repo_type="space",
operations=[CommitOperationAdd(path_in_repo="file.py", path_or_fileobj=temp_file)],
commit_message="Fix something",
)
Create PR:

Use create_discussion() to create a PR (pull request):

api.create_discussion(
repo_id="OpenHands/openhands-index",
repo_type="space",
title="PR title",
description="Description",
pull_request=True,
repo_revision="branch-name", # source branch
)

juan-all-hands pinned discussion

Sign up or log in to comment