RaheelShah commited on
Commit
c03f3fe
·
1 Parent(s): c8df25c

Update GitHub Actions workflow for Image Classifier project

Browse files
Files changed (1) hide show
  1. .github/workflows/deploy.yml +92 -0
.github/workflows/deploy.yml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy Image Classifier to Hugging Face Spaces
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ deploy:
10
+ runs-on: ubuntu-latest
11
+ environment: hugging_face_env
12
+ steps:
13
+ # 1. Checkout code
14
+ - name: Checkout Repository
15
+ uses: actions/checkout@v3
16
+ with:
17
+ lfs: true
18
+
19
+ # 2. Setup Python
20
+ - name: Set Up Python
21
+ uses: actions/setup-python@v4
22
+ with:
23
+ python-version: '3.11'
24
+
25
+ # 3. Install system dependencies for OpenCV and MediaPipe
26
+ - name: Install System Dependencies
27
+ run: |
28
+ sudo apt-get update
29
+ sudo apt-get install -y \
30
+ git \
31
+ git-lfs \
32
+ libsm6 \
33
+ libxext6 \
34
+ libxrender-dev \
35
+ libgl1 \
36
+ libglib2.0-0 \
37
+ libgomp1 \
38
+ libglx-mesa0 \
39
+ ffmpeg \
40
+ rsync
41
+ git lfs install
42
+
43
+ # 4. Install Python dependencies
44
+ - name: Install Dependencies
45
+ run: |
46
+ python -m pip install --upgrade pip
47
+ pip install --no-cache-dir -r requirements.txt
48
+ pip install --no-cache-dir "huggingface-hub>=0.30" hf-transfer>=0.1.4
49
+
50
+ # 5. Configure git for Hugging Face
51
+ - name: Configure Git User
52
+ run: |
53
+ git config --global user.name "github-actions[bot]"
54
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
55
+
56
+ # 6. Deploy to Hugging Face Space
57
+ - name: Deploy to Hugging Face Space
58
+ env:
59
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
60
+ HF_USERNAME: ${{ secrets.HF_USERNAME }}
61
+ HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
62
+ run: |
63
+ # Store credentials securely
64
+ echo "https://$HF_USERNAME:$HF_TOKEN@huggingface.co" > ~/.git-credentials
65
+ git config --global credential.helper store
66
+
67
+ # Clone the space repository
68
+ git clone https://huggingface.co/spaces/$HF_USERNAME/$HF_SPACE_NAME repo
69
+
70
+ # Copy files to the repo directory (exclude unnecessary files)
71
+ rsync -av --exclude={'.git','repo','.github','__pycache__','*.pyc','*.log','.env','venv','env','.vscode'} ./ repo/
72
+
73
+ # Commit and push
74
+ cd repo
75
+
76
+ # Track binary files with Git LFS
77
+ git lfs track "*.tflite"
78
+ git lfs track "*.png"
79
+ git lfs track "*.jpg"
80
+ git lfs track "*.jpeg"
81
+
82
+ git add .gitattributes
83
+ git add .
84
+ git commit -m "🛒 Automated Image Classifier deployment from GitHub Actions" || echo "No changes to commit"
85
+ git push https://huggingface.co/spaces/$HF_USERNAME/$HF_SPACE_NAME main
86
+
87
+ # 7. Cleanup credentials
88
+ - name: Cleanup Credentials
89
+ if: always()
90
+ run: |
91
+ rm -f ~/.git-credentials
92
+