Spaces:
Running
Running
Commit
Β·
8a23417
1
Parent(s):
b38b9a9
π Add GitHub Actions workflow for HuggingFace Spaces deployment
Browse files- Automatically sync repository to HF Spaces on every push
- Auto-detects HuggingFace username from token
- Configurable Space name via environment variable
- Includes manual workflow dispatch option
- Robust error handling and logging
.github/workflows/sync_to_huggingface.yml
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to HuggingFace Spaces
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [main, master]
|
| 6 |
+
workflow_dispatch: # Allow manual triggering
|
| 7 |
+
|
| 8 |
+
env:
|
| 9 |
+
HF_SPACE_NAME: "textlens-ocr" # Change this to your Space name if different
|
| 10 |
+
|
| 11 |
+
jobs:
|
| 12 |
+
sync-to-huggingface:
|
| 13 |
+
runs-on: ubuntu-latest
|
| 14 |
+
|
| 15 |
+
steps:
|
| 16 |
+
- name: Checkout repository
|
| 17 |
+
uses: actions/checkout@v4
|
| 18 |
+
with:
|
| 19 |
+
fetch-depth: 0
|
| 20 |
+
lfs: true
|
| 21 |
+
|
| 22 |
+
- name: Setup Python
|
| 23 |
+
uses: actions/setup-python@v4
|
| 24 |
+
with:
|
| 25 |
+
python-version: "3.9"
|
| 26 |
+
|
| 27 |
+
- name: Install HuggingFace Hub
|
| 28 |
+
run: |
|
| 29 |
+
pip install huggingface_hub
|
| 30 |
+
|
| 31 |
+
- name: Setup Git
|
| 32 |
+
run: |
|
| 33 |
+
git config --global user.email "[email protected]"
|
| 34 |
+
git config --global user.name "GitHub Action"
|
| 35 |
+
|
| 36 |
+
- name: Get HuggingFace username
|
| 37 |
+
id: hf_user
|
| 38 |
+
env:
|
| 39 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 40 |
+
run: |
|
| 41 |
+
# Get username from HuggingFace API
|
| 42 |
+
python -c "
|
| 43 |
+
from huggingface_hub import HfApi
|
| 44 |
+
import os
|
| 45 |
+
api = HfApi(token=os.environ['HF_TOKEN'])
|
| 46 |
+
user = api.whoami()
|
| 47 |
+
print(f\"HF_USERNAME={user['name']}\")
|
| 48 |
+
" >> $GITHUB_OUTPUT
|
| 49 |
+
|
| 50 |
+
- name: Push to HuggingFace Spaces
|
| 51 |
+
env:
|
| 52 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 53 |
+
HF_USERNAME: ${{ steps.hf_user.outputs.HF_USERNAME }}
|
| 54 |
+
run: |
|
| 55 |
+
# Create the HuggingFace Space URL
|
| 56 |
+
HF_SPACE_URL="https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}"
|
| 57 |
+
|
| 58 |
+
echo "Syncing to: $HF_SPACE_URL"
|
| 59 |
+
|
| 60 |
+
# Push to HuggingFace Spaces
|
| 61 |
+
git push --force https://user:[email protected]/spaces/${HF_USERNAME}/${HF_SPACE_NAME} HEAD:main
|
| 62 |
+
|
| 63 |
+
echo "β
Successfully synced to HuggingFace Spaces!"
|
| 64 |
+
echo "π Your Space will be available at: $HF_SPACE_URL"
|