I’ve used Hugging Face Space for my daily job. However, right now only 2 people are using repos, so we are updating the main branch directly since Hugging Face repo’s git system is different from GitHub and it’s not software engineer friendly. They have their system.
Our Pull requests do not use forks and branches, but instead custom “branches” called refs that are stored directly on the source repo.
Then I found a GitHub Action, Sync With Hugging Face Hub.
Next, we would need to create a new space. In this post, we will create a simple UI with Gradio so we will need to create a Gradiospace.
Hugging Face Space
Step 3 Setup GitHub Action
Now we need to set up GitHub Action to sync two repos via GitHub Action. In this case, the action is kicked when we merge a branch into the main branch.
First, we need to clone the repo we created in step 1. The following command is what I created to test the GitHub Actions. You need to replace the repo URL with yours.
git clone https://github.com/koji/hugging_face_space.git
git cd hugging_face_space
git checkout -b chore_setup-github-actions
Then create two folders for GitHub Actions.
.github
.github/workflows
We will add a yaml file to workflows. I named push_to_hf_space.yml but you can name whatever you want.
name:Sync with Hugging Face Hubon:push:branches:-mainjobs:build:runs-on:ubuntu-lateststeps:-name:Sync with Hugging Faceuses:nateraw/huggingface-sync-action@v0.0.4with:github_repo_id:your_github_repo_idhuggingface_repo_id:your_hugging_face_repo_idrepo_type:spacespace_sdk:gradiohf_token:${{ secrets.HF_TOKEN }}
Before pushing the change to your GitHub repo, we will need to add two more files. One is app.py for a Gradio app and the other is readme.md. When you create a repo on GitHub, you might generate readme.md too. However, we need to update that for Hugging Face space since for space, readme.md is a special file for running a Docker image.