Spaces:
Sleeping
Sleeping
Deploy Myco from GitHub Actions
Browse files- 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 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 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
|
| 38 |
|
| 39 |
|
| 40 |
def main() -> None:
|
|
@@ -47,18 +47,28 @@ def main() -> None:
|
|
| 47 |
)
|
| 48 |
return
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
repo_id = get_space_id()
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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__":
|