amanydv2112's picture
Upload folder using huggingface_hub
bcdb14b verified
Raw
History Blame Contribute Delete
1.5 kB
name: Deploy to Hugging Face Spaces
on:
push:
branches: [master]
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Install huggingface_hub
run: pip install huggingface_hub
- name: Upload to Hugging Face Spaces
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_SPACE_ID: ${{ vars.HF_SPACE_ID }}
run: |
python - <<'EOF'
import os
from huggingface_hub import HfApi
api = HfApi(token=os.environ["HF_TOKEN"])
space_id = os.environ["HF_SPACE_ID"]
ignore = [
".git", ".gitattributes", ".venv", "__pycache__",
"*.pyc", ".env", ".cursor", ".DS_Store",
"data/embeddings.azure*.npy", "data/embeddings.gemini*.npy",
]
# Upload everything except README first (avoids HF YAML validation API call)
api.upload_folder(
folder_path=".",
repo_id=space_id,
repo_type="space",
ignore_patterns=ignore + ["README.md"],
)
# Upload README as plain file (no YAML validation triggered)
api.upload_file(
path_or_fileobj="README.md",
path_in_repo="README.md",
repo_id=space_id,
repo_type="space",
)
print(f"Deployed to {space_id}")
EOF