Update to HF deployment #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Hugging Face Spaces | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| pip install huggingface_hub | |
| # Install Git LFS | |
| sudo apt-get update | |
| sudo apt-get install -y git-lfs | |
| git lfs install | |
| - name: Push to Hugging Face Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN }} | |
| run: | | |
| # Check if HUGGINGFACE_SPACE_REPO is set | |
| if [ -z "${{ secrets.HUGGINGFACE_SPACE_REPO }}" ]; then | |
| echo "HUGGINGFACE_SPACE_REPO secret not set. Please set it to your space repository name (e.g., 'username/nemaquant')" | |
| exit 1 | |
| fi | |
| # Create a temporary directory for the space | |
| mkdir -p space_repo | |
| cd space_repo | |
| # Configure git credentials for Hugging Face | |
| git config --global credential.helper store | |
| echo "https://user:${HF_TOKEN}@huggingface.co" > ~/.git-credentials | |
| # Set default branch to main | |
| git config --global init.defaultBranch main | |
| # Initialize git repository with LFS | |
| git init | |
| git lfs install | |
| git remote add origin https://huggingface.co/spaces/${{ secrets.HUGGINGFACE_SPACE_REPO }} | |
| # Create .gitattributes for LFS BEFORE copying files | |
| echo "*.pt filter=lfs diff=lfs merge=lfs -text" > .gitattributes | |
| echo "*.pth filter=lfs diff=lfs merge=lfs -text" >> .gitattributes | |
| echo "*.bin filter=lfs diff=lfs merge=lfs -text" >> .gitattributes | |
| echo "*.h5 filter=lfs diff=lfs merge=lfs -text" >> .gitattributes | |
| echo "*.onnx filter=lfs diff=lfs merge=lfs -text" >> .gitattributes | |
| # Copy necessary files | |
| cp ../README.md . | |
| cp ../app.py . | |
| cp ../requirements.txt . | |
| cp ../Dockerfile . | |
| cp ../yolo_utils.py . | |
| cp -r ../templates . | |
| cp -r ../static . | |
| # Copy model weights if they exist | |
| if [ -f ../weights.pt ]; then | |
| echo "Found weights.pt, copying..." | |
| cp ../weights.pt . | |
| fi | |
| # Add and commit | |
| git add .gitattributes | |
| git add . | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git commit -m "Update NemaQuant app from GitHub Actions - ${{ github.sha }}" | |
| # Push to Hugging Face Space (force push to handle initial setup) | |
| git push --force origin main | |
| - name: Summary | |
| run: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Hugging Face Space**: \`https://huggingface.co/spaces/${{ secrets.HUGGINGFACE_SPACE_REPO }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Successfully deployed to HF Spaces" >> $GITHUB_STEP_SUMMARY | |
| if [ -f space_repo/weights.pt ]; then | |
| echo "- **Model weights**: Included via Git LFS" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- **Model weights**: Not found (add weights.pt to enable)" >> $GITHUB_STEP_SUMMARY | |
| fi |