mlstocks / .github /workflows /hf_deploy.yml
github-actions[bot]
Deploy to Hugging Face Space
abf702c
name: Deploy to Hugging Face Spaces
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install huggingface_hub
- name: Ensure Space Exists
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: ${{ secrets.HF_USERNAME }}
SPACE_NAME: mlstocks
run: |
python -c "
from huggingface_hub import create_repo
import os
token = os.environ['HF_TOKEN']
user = os.environ['HF_USERNAME']
space_name = os.environ['SPACE_NAME']
repo_id = f'{user}/{space_name}'
print(f'Checking/Creating Space: {repo_id}')
try:
create_repo(
repo_id=repo_id,
token=token,
repo_type='space',
space_sdk='docker',
exist_ok=True
)
print('Space is ready.')
except Exception as e:
print(f'Error creating space: {e}')
exit(1)
"
- name: Push to Hugging Face Hub
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: ${{ secrets.HF_USERNAME }}
SPACE_NAME: mlstocks
run: |
# 1. Configure Identity
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# 2. DELETE existing git history to destroy any traces of binary blobs
rm -rf .git
# 3. Initialize fresh repo for deployment
git init
git lfs install
# 4. Enforce LFS for .db files
echo "*.db filter=lfs diff=lfs merge=lfs -text" > .gitattributes
# 5. Add files (LFS filter will apply now because .gitattributes exists before add)
git add .
# 6. Commit
git commit -m "Deploy to Hugging Face Space"
# 7. Push
git remote add space https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
git push --force space master:main