ALYYAN commited on
Commit
3c8745e
·
1 Parent(s): e21c44d

updated main.yaml

Browse files
Files changed (1) hide show
  1. .github/workflows/main.yaml +19 -21
.github/workflows/main.yaml CHANGED
@@ -5,30 +5,28 @@ name: Deploy App to Hugging Face Spaces
5
  on:
6
  push:
7
  branches:
8
- - main # Trigger this workflow on every push to the main branch
9
 
10
  jobs:
11
  deploy-to-hub:
12
  runs-on: ubuntu-latest
13
 
14
  steps:
15
- # Step 1: Check out your source code from GitHub
16
  - name: Checkout repository
17
  uses: actions/checkout@v4
18
  with:
19
- fetch-depth: 0 # Fetches all history for Git LFS
20
 
21
- # Step 2: Set up Python environment
22
  - name: Set up Python
23
  uses: actions/setup-python@v5
24
  with:
25
- python-version: '3.11' # Match the Python version you used
26
 
27
- # Step 3: Install DVC and its Google Drive dependency
28
- - name: Install DVC
29
- run: pip install "dvc[gdrive]"
 
30
 
31
- # Step 4: Configure DVC with the credentials from GitHub Secrets
32
  - name: Configure DVC
33
  env:
34
  GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }}
@@ -36,29 +34,29 @@ jobs:
36
  mkdir -p .dvc/tmp
37
  echo "$GDRIVE_CREDENTIALS_DATA" > .dvc/tmp/gdrive-user-credentials.json
38
 
39
- # Step 5: Pull the large model file from Google Drive
40
  - name: Pull DVC Artifacts
41
  run: dvc pull artifacts/model_training/model.dvc -f
42
 
43
- # Step 6: Log in to Hugging Face Hub
44
  - name: Log in to Hugging Face Hub
45
- uses: huggingface-hub/login@v1
46
- with:
47
- token: ${{ secrets.HF_TOKEN }}
 
 
 
48
 
49
- # Step 7: Push the complete app (code + model) to the Space
50
  - name: Push to HF Space
51
  env:
52
- HF_SPACE_TARGET: ${{ secrets.HF_USERNAME }}/${{ secrets.HF_SPACE_NAME }} # Example: ALYYAN/pneumonia-detection-ai
 
53
  run: |
54
  git config --global user.email "action@github.com"
55
  git config --global user.name "GitHub Action"
56
- # Clone the Space repo into a new directory
57
- git clone https://huggingface.co/spaces/${HF_SPACE_TARGET} hf_space_repo
58
- # Copy all necessary files into the Space repo
59
- cp -r app/ app.py requirements.txt README.md artifacts/model_training/model/ hf_space_repo/
60
  cd hf_space_repo
61
- # Commit and push
62
  git add .
63
  git commit -m "Automatic deployment from GitHub Action" || echo "No changes to commit"
64
  git push
 
5
  on:
6
  push:
7
  branches:
8
+ - main
9
 
10
  jobs:
11
  deploy-to-hub:
12
  runs-on: ubuntu-latest
13
 
14
  steps:
 
15
  - name: Checkout repository
16
  uses: actions/checkout@v4
17
  with:
18
+ fetch-depth: 0
19
 
 
20
  - name: Set up Python
21
  uses: actions/setup-python@v5
22
  with:
23
+ python-version: '3.11'
24
 
25
+ - name: Install DVC and project requirements
26
+ run: |
27
+ pip install "dvc[gdrive]"
28
+ pip install -r requirements.txt # requirements.txt should also have huggingface_hub
29
 
 
30
  - name: Configure DVC
31
  env:
32
  GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }}
 
34
  mkdir -p .dvc/tmp
35
  echo "$GDRIVE_CREDENTIALS_DATA" > .dvc/tmp/gdrive-user-credentials.json
36
 
 
37
  - name: Pull DVC Artifacts
38
  run: dvc pull artifacts/model_training/model.dvc -f
39
 
40
+ # --- THIS IS THE FIX ---
41
  - name: Log in to Hugging Face Hub
42
+ env:
43
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
44
+ run: |
45
+ # huggingface_hub is already installed via requirements.txt, but this is a safe fallback
46
+ pip install huggingface_hub
47
+ huggingface-cli login --token $HF_TOKEN
48
 
 
49
  - name: Push to HF Space
50
  env:
51
+ HF_USERNAME: ${{ secrets.HF_USERNAME }}
52
+ HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
53
  run: |
54
  git config --global user.email "action@github.com"
55
  git config --global user.name "GitHub Action"
56
+ git clone https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME} hf_space_repo
57
+ # Use rsync for a more robust copy
58
+ rsync -av --delete app/ app.py requirements.txt README.md artifacts/model_training/model/ hf_space_repo/
 
59
  cd hf_space_repo
 
60
  git add .
61
  git commit -m "Automatic deployment from GitHub Action" || echo "No changes to commit"
62
  git push