DEV Community

Cover image for Sync GitHub repo and Hugging Face Space Repo with GitHub Actions

Posted on

Sync GitHub repo and Hugging Face Space Repo with GitHub Actions

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.

The steps to sync GitHub repo and Hugging Face Space repo are very easy with that.



Step 1 Create a repo on GitHub

First, we need to create a repository on GitHub.

Step 2 Create a space on Hugging Face

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
git cd hugging_face_space
git checkout -b chore_setup-github-actions
Then create two folders for GitHub Actions.
Enter fullscreen mode Exit fullscreen mode



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 Hub

      - main

    runs-on: ubuntu-latest
    - name: Sync with Hugging Face
      uses: nateraw/huggingface-sync-action@v0.0.4
        github_repo_id: your_github_repo_id
        huggingface_repo_id: your_hugging_face_repo_id
        repo_type: space
        space_sdk: gradio
        hf_token: ${{ secrets.HF_TOKEN }}
Enter fullscreen mode Exit fullscreen mode

Mine is here.

Before pushing the change to your GitHub repo, we will need to add two more files. One is for a Gradio app and the other is When you create a repo on GitHub, you might generate too. However, we need to update that for Hugging Face space since for space, is a special file for running a Docker image.

import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
Enter fullscreen mode Exit fullscreen mode

My readme is like below. You can get your own readme file from your Hugging Face Space Files.

title: "Gh Action"
emoji: 🐨
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 4.14.0
pinned: false
license: mit
Enter fullscreen mode Exit fullscreen mode

Check out the configuration reference at
Now it’s time to test GitHub Actions. We need push our changes to the GitHub repository.

git add .
git commit -m "set up GitHub Actions and add a simple gradio app"
git push 
Enter fullscreen mode Exit fullscreen mode

After finishing pushing your branch, you just need to merge your branch into edge.

Then you can go to your Hugging Face Space, and you will see something like this.

My repo for this

Top comments (0)