byte-vortex commited on
Commit
4cc2f21
·
verified ·
1 Parent(s): 231d560

Deploy Myco from GitHub Actions

Browse files
Files changed (1) hide show
  1. scripts/deploy_space.py +34 -24
scripts/deploy_space.py CHANGED
@@ -7,19 +7,19 @@ import os
7
  TOKEN_ENV_VAR = "HF_BUILD_SMALL_HACKATHON_TOKEN"
8
  DEFAULT_SPACE_ID = "byte-vortex/Myco"
9
 
10
- IGNORE_PATTERNS = (
11
- ".git/*",
12
- ".github/*",
13
- "__pycache__/*",
14
- "**/__pycache__/*",
15
- "*.pyc",
16
- ".gradio/*",
17
- ".cache/*",
18
- "models/downloads/*",
19
- "models/**/*.gguf",
20
- "models/**/*.bin",
21
- "models/**/*.safetensors",
22
- )
23
 
24
 
25
  def get_hf_token() -> str:
@@ -34,7 +34,7 @@ def get_space_id() -> str:
34
 
35
  def get_ignore_patterns() -> list[str]:
36
  """Return upload ignore patterns as a list for huggingface_hub."""
37
- return list(IGNORE_PATTERNS)
38
 
39
 
40
  def main() -> None:
@@ -47,18 +47,28 @@ def main() -> None:
47
  )
48
  return
49
 
50
- from huggingface_hub import HfApi
 
 
 
 
51
 
52
  repo_id = get_space_id()
53
- HfApi().upload_folder(
54
- folder_path=".",
55
- repo_id=repo_id,
56
- repo_type="space",
57
- token=token,
58
- ignore_patterns=get_ignore_patterns(),
59
- commit_message="Deploy Myco from GitHub Actions",
60
- )
61
- print(f"Deployed Myco to https://huggingface.co/spaces/{repo_id}")
 
 
 
 
 
 
62
 
63
 
64
  if __name__ == "__main__":
 
7
  TOKEN_ENV_VAR = "HF_BUILD_SMALL_HACKATHON_TOKEN"
8
  DEFAULT_SPACE_ID = "byte-vortex/Myco"
9
 
10
+ IGNORE_PATTERNS_TEXT = """
11
+ .git/*
12
+ .github/*
13
+ __pycache__/*
14
+ **/__pycache__/*
15
+ *.pyc
16
+ .gradio/*
17
+ .cache/*
18
+ models/downloads/*
19
+ models/**/*.gguf
20
+ models/**/*.bin
21
+ models/**/*.safetensors
22
+ """
23
 
24
 
25
  def get_hf_token() -> str:
 
34
 
35
  def get_ignore_patterns() -> list[str]:
36
  """Return upload ignore patterns as a list for huggingface_hub."""
37
+ return [pattern for pattern in IGNORE_PATTERNS_TEXT.splitlines() if pattern]
38
 
39
 
40
  def main() -> None:
 
47
  )
48
  return
49
 
50
+ try:
51
+ from huggingface_hub import HfApi
52
+ except ImportError:
53
+ print("::warning::huggingface_hub not installed. Skipping deployment.")
54
+ return
55
 
56
  repo_id = get_space_id()
57
+ print(f"Deploying to Space: {repo_id}")
58
+
59
+ try:
60
+ HfApi().upload_folder(
61
+ folder_path=".",
62
+ repo_id=repo_id,
63
+ repo_type="space",
64
+ token=token,
65
+ ignore_patterns=get_ignore_patterns(),
66
+ commit_message="Deploy Myco from GitHub Actions",
67
+ )
68
+ print(f"✅ Successfully deployed Myco to https://huggingface.co/spaces/{repo_id}")
69
+ except Exception as e:
70
+ print(f"::error::Failed to deploy to HF Space: {e}")
71
+ raise
72
 
73
 
74
  if __name__ == "__main__":