Create a huggingface token
Put it in the repo secrets with name like HF_TOKEN
in related Github repo setitngs:
- https://github.com/<user_name>/<repo_name>/settings/secrets/actions
Run following commands in the git root folder:
git remote add space https://huggingface.co/spaces/<user_name>/<repo_name>
# git remote -v
git remote set-url space https://<user_name>:<token>@huggingface.co/spaces/<user_name>/<repo_name>
git push --force space main
<repo_path>
is in the form of:- models:
<user_name>/<repo_name>
- datasets:
datasets/<user_name>/<repo_name>
- spaces:
spaces/<user_name>/<repo_name>
- models:
Then add a sync_to_huggingface_space.yml
in .github/workflows
:
- Replace the
<user_name>
(x2) and<repo_name>
in the last line for current repo. - The
HF_TOKEN
name should be the same with the one specified in the step above.
name: Sync to Hugging Face hub
on:
push:
branches: [main]
workflow_dispatch:
jobs:
sync-to-hub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: true
- name: Push to hub
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: git push -f https://<user_name>:[email protected]/spaces/<user_name>/<repo_name> main
-
Managing Spaces with Github Actions
-
Hugging Face - settings > tokens