Hub 文件

使用Github Actions管理Spaces

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

使用 Github Actions 管理 Spaces

你可以使用 Github Actions 使你的應用與你的 GitHub 倉庫保持同步。請注意,對於大於 10MB 的檔案,Spaces 需要 Git-LFS。如果你不想使用 Git-LFS,你可能需要檢查你的檔案和歷史記錄。使用像 BFG Repo-Cleaner 這樣的工具來從你的歷史記錄中刪除任何大檔案。BFG Repo-Cleaner 會保留你倉庫的本地副本作為備份。

首先,你應該將你的 GitHub 倉庫和 Spaces 應用設定在一起。將你的 Spaces 應用作為額外的遠端倉庫新增到你現有的 Git 倉庫中。

git remote add space https://huggingface.co/spaces/HF_USERNAME/SPACE_NAME

然後強制推送以首次同步所有內容

git push --force space main

接下來,設定一個 GitHub Action,將你的主分支推送到 Spaces。在下面的示例中

  • HF_USERNAME 替換為你的使用者名稱,將 SPACE_NAME 替換為你的 Space 名稱。
  • 使用你的 HF_TOKEN 建立一個 Github secret。你可以在你的 Hugging Face 個人資料的 API Tokens 下找到你的 Hugging Face API 令牌。
name: Sync to Hugging Face hub
on:
  push:
    branches: [main]

  # to run this workflow manually from the Actions tab
  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 https://HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/HF_USERNAME/SPACE_NAME main

最後,建立一個 Action,自動檢查任何新拉取請求的檔案大小

name: Check file size
on:               # or directly `on: [push]` to run the action on every push on any branch
  pull_request:
    branches: [main]

  # to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  sync-to-hub:
    runs-on: ubuntu-latest
    steps:
      - name: Check large files
        uses: ActionsDesk/lfs-warning@v2.0
        with:
          filesizelimit: 10485760 # this is 10MB so we can sync to HF Spaces
< > 在 GitHub 上更新

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