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 token。
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