-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (54 loc) · 1.83 KB
/
Copy pathdeploy-space.yml
File metadata and controls
62 lines (54 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Deploy to HuggingFace Space
on:
push:
branches: [ main ]
paths: [ 'backend/**' ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install HuggingFace Hub
run: pip install huggingface_hub
- name: Sync backend to HuggingFace Space
run: |
python -c "
from huggingface_hub import HfApi, create_repo
import os
api = HfApi(token=os.environ['HF_TOKEN'])
repo_id = os.environ['HF_SPACE_ID']
# Try to create the space if it doesn't exist
space_created = False
try:
create_repo(
repo_id=repo_id,
repo_type='space',
token=os.environ['HF_TOKEN'],
space_sdk='docker',
private=False
)
print(f'Created space: {repo_id}')
space_created = True
except Exception as e:
if 'already exists' in str(e).lower() or 'conflict' in str(e).lower():
print(f'Space {repo_id} already exists, continuing with upload...')
else:
print(f'Warning: Could not create space: {e}')
print('Attempting to upload anyway (space might exist)...')
# Always try to upload files from backend directory
try:
api.upload_folder(
folder_path='backend',
repo_id=repo_id,
repo_type='space',
token=os.environ['HF_TOKEN']
)
print(f'Successfully synced backend to {repo_id}')
except Exception as e:
print(f'Error uploading files: {e}')
raise e
"
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_SPACE_ID: ${{ secrets.HF_SPACE_ID }}