Hub 文档
使用Github Actions管理Spaces
加入 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