crosse712 commited on
Commit
fadb62b
Β·
1 Parent(s): 0bfacdd

Add GitHub Actions workflows for automatic Hugging Face Space sync

Browse files
.github/workflows/README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # GitHub Actions Workflows
2
+
3
+ This repository uses GitHub Actions to automatically sync changes to Hugging Face Spaces.
4
+
5
+ ## Workflows
6
+
7
+ ### 1. sync-to-huggingface.yml
8
+ - **Trigger**: Push to main branch or manual dispatch
9
+ - **Method**: Direct git push to Hugging Face Space
10
+ - **Speed**: Fast, simple approach
11
+
12
+ ### 2. sync-hf-space.yml
13
+ - **Trigger**: Push to main, PR to main, or manual dispatch
14
+ - **Method**: Uses huggingface_hub Python library
15
+ - **Features**: More control over file uploads, ignore patterns
16
+
17
+ ## Setup Instructions
18
+
19
+ ### Step 1: Get Hugging Face Token
20
+ 1. Go to: https://huggingface.co/settings/tokens
21
+ 2. Click "New token"
22
+ 3. Name: `github-actions`
23
+ 4. Role: `write`
24
+ 5. Copy the token
25
+
26
+ ### Step 2: Add Token to GitHub Secrets
27
+ 1. Go to your GitHub repo: https://github.com/crosse712/fastvlm-screen-observer
28
+ 2. Navigate to: Settings β†’ Secrets and variables β†’ Actions
29
+ 3. Click "New repository secret"
30
+ 4. Name: `FASTVLM_API`
31
+ 5. Value: Paste your Hugging Face token
32
+ 6. Click "Add secret"
33
+
34
+ ### Step 3: Enable Workflow
35
+ The workflows will automatically run when you:
36
+ - Push to the main branch
37
+ - Create a pull request
38
+ - Manually trigger from Actions tab
39
+
40
+ ## Manual Trigger
41
+ 1. Go to: https://github.com/crosse712/fastvlm-screen-observer/actions
42
+ 2. Select a workflow
43
+ 3. Click "Run workflow"
44
+ 4. Select branch and run
45
+
46
+ ## Monitoring
47
+ - Check workflow runs: https://github.com/crosse712/fastvlm-screen-observer/actions
48
+ - View Space build logs: https://huggingface.co/spaces/crosse712/fastvlm-screen-observer
.github/workflows/sync-hf-space.yml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to HF Space (Official Action)
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+ workflow_dispatch:
11
+
12
+ env:
13
+ HF_SPACE_ID: crosse712/fastvlm-screen-observer
14
+
15
+ jobs:
16
+ sync:
17
+ runs-on: ubuntu-latest
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 0
24
+ lfs: true
25
+
26
+ - name: Setup Python
27
+ uses: actions/setup-python@v5
28
+ with:
29
+ python-version: '3.9'
30
+
31
+ - name: Install huggingface_hub
32
+ run: pip install huggingface_hub
33
+
34
+ - name: Sync to Hugging Face Space
35
+ env:
36
+ HF_TOKEN: ${{ secrets.FASTVLM_API }}
37
+ run: |
38
+ python -c "
39
+ from huggingface_hub import HfApi
40
+ import os
41
+
42
+ api = HfApi()
43
+ space_id = '${{ env.HF_SPACE_ID }}'
44
+ token = os.environ.get('HF_TOKEN')
45
+
46
+ # Upload all files to the Space
47
+ api.upload_folder(
48
+ folder_path='.',
49
+ repo_id=space_id,
50
+ repo_type='space',
51
+ token=token,
52
+ commit_message='Sync from GitHub: ${{ github.event.head_commit.message }}',
53
+ ignore_patterns=['*.git*', '.github/**', '__pycache__/**', '*.pyc', 'venv/**', 'node_modules/**']
54
+ )
55
+
56
+ print(f'βœ… Successfully synced to {space_id}')
57
+ "
58
+
59
+ - name: Display Space URL
60
+ run: |
61
+ echo "πŸš€ Deployment triggered!"
62
+ echo "πŸ”— Space URL: https://huggingface.co/spaces/${{ env.HF_SPACE_ID }}"
63
+ echo "πŸ“Š Check the Space for build status and logs"
.github/workflows/sync-to-huggingface.yml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face Space
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch: # Allows manual triggering
8
+
9
+ jobs:
10
+ sync-to-space:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout repository
15
+ uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 0
18
+ lfs: true
19
+
20
+ - name: Push to Hugging Face Space
21
+ env:
22
+ HF_TOKEN: ${{ secrets.FASTVLM_API }}
23
+ run: |
24
+ # Add Hugging Face as a remote
25
+ git remote add space https://crosse712:$HF_TOKEN@huggingface.co/spaces/crosse712/fastvlm-screen-observer
26
+
27
+ # Force push to the Space (this will overwrite the Space with the GitHub repo)
28
+ git push --force space main
29
+
30
+ - name: Verify deployment
31
+ run: |
32
+ echo "βœ… Successfully synced to Hugging Face Space!"
33
+ echo "πŸ”— View your Space: https://huggingface.co/spaces/crosse712/fastvlm-screen-observer"
34
+ echo "πŸ“Š Check build logs in the Space UI for deployment status"