RaheelShah's picture
Update GitHub Actions workflow for Image Classifier project
c03f3fe
name: Deploy Image Classifier to Hugging Face Spaces
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
environment: hugging_face_env
steps:
# 1. Checkout code
- name: Checkout Repository
uses: actions/checkout@v3
with:
lfs: true
# 2. Setup Python
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
# 3. Install system dependencies for OpenCV and MediaPipe
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
git \
git-lfs \
libsm6 \
libxext6 \
libxrender-dev \
libgl1 \
libglib2.0-0 \
libgomp1 \
libglx-mesa0 \
ffmpeg \
rsync
git lfs install
# 4. Install Python dependencies
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir "huggingface-hub>=0.30" hf-transfer>=0.1.4
# 5. Configure git for Hugging Face
- name: Configure Git User
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# 6. Deploy to Hugging Face Space
- name: Deploy to Hugging Face Space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: ${{ secrets.HF_USERNAME }}
HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
run: |
# Store credentials securely
echo "https://$HF_USERNAME:$HF_TOKEN@huggingface.co" > ~/.git-credentials
git config --global credential.helper store
# Clone the space repository
git clone https://huggingface.co/spaces/$HF_USERNAME/$HF_SPACE_NAME repo
# Copy files to the repo directory (exclude unnecessary files)
rsync -av --exclude={'.git','repo','.github','__pycache__','*.pyc','*.log','.env','venv','env','.vscode'} ./ repo/
# Commit and push
cd repo
# Track binary files with Git LFS
git lfs track "*.tflite"
git lfs track "*.png"
git lfs track "*.jpg"
git lfs track "*.jpeg"
git add .gitattributes
git add .
git commit -m "๐Ÿ›’ Automated Image Classifier deployment from GitHub Actions" || echo "No changes to commit"
git push https://huggingface.co/spaces/$HF_USERNAME/$HF_SPACE_NAME main
# 7. Cleanup credentials
- name: Cleanup Credentials
if: always()
run: |
rm -f ~/.git-credentials