Hub 文件

GitHub Actions

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

GitHub Actions

您可以使用 GitHub Actions 自動將您的 GitHub 儲存庫同步至 Hugging Face Hub。官方的 huggingface/hub-sync Action 支援同步模型 (Models)資料集 (Datasets)Spaces

設定

  1. 建立一個擁有目標儲存庫 寫入 (write) 權限的 Hugging Face 存取權杖 (access token)。為了提升安全性,建議使用細粒度權杖 (fine-grained token),並僅限於您要同步的該儲存庫使用。
  2. 在您的儲存庫設定中,將該權杖加入名為 HF_TOKENGitHub Secret
  3. 在您的儲存庫中加入工作流程檔案(例如 .github/workflows/sync-to-hub.yml)。

基本用法

name: Sync to Hugging Face Hub
on:
  push:
    branches: [main]

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: huggingface/hub-sync@v0.1.0
        with:
          github_repo_id: ${{ github.repository }}
          huggingface_repo_id: username/repo-name
          hf_token: ${{ secrets.HF_TOKEN }}

預設情況下,此動作會同步至 Space。若要同步模型或資料集,請設定 repo_type 參數。

      - uses: huggingface/hub-sync@v0.1.0
        with:
          github_repo_id: ${{ github.repository }}
          huggingface_repo_id: username/my-dataset
          hf_token: ${{ secrets.HF_TOKEN }}
          repo_type: dataset

參數

參數 必要 預設 說明
github_repo_id GitHub 儲存庫(使用 ${{ github.repository }}
huggingface_repo_id Hub 上的目標儲存庫(使用者名稱/儲存庫名稱
hf_token Hugging Face 存取權杖
repo_type space spacemodeldataset
space_sdk gradio gradiostreamlitdockerstatic
private false 是否將儲存庫建立為私人 (private)
subdirectory . 同步指定的子目錄(對於單一儲存庫 (monorepo) 非常實用)

此 Action 使用 hf CLI 將您的檔案鏡像同步至 Hub — 這並非 git 對 git 的同步。它會自動排除 .github/.git/ 目錄,並鏡像同步刪除操作(即從 GitHub 移除的檔案也會從 Hub 中移除)。

若有更複雜的工作流程(例如建置步驟、自訂上傳邏輯),您可以直接在工作流程中安裝並使用 hf CLI

有關 Spaces 的特定指引(檔案大小限制、LFS 處理方式),請參閱使用 GitHub Actions 管理 Spaces 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.