| | 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: |
|
| |
|
| | git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
| | git config --global user.name "github-actions[bot]"
|
| |
|
| |
|
| | rm -rf .git
|
| |
|
| |
|
| | git init
|
| | git lfs install
|
| |
|
| |
|
| | echo "*.db filter=lfs diff=lfs merge=lfs -text" > .gitattributes
|
| |
|
| |
|
| | git add .
|
| |
|
| |
|
| | git commit -m "Deploy to Hugging Face Space"
|
| |
|
| |
|
| | git remote add space https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
|
| | git push --force space master:main
|
| |
|