Spaces:
Running
Running
| """Optional Hugging Face Space deploy helper. | |
| This script is intentionally minimal because CI may call it directly. If the | |
| optional HF_BUILD_SMALL_HACKATHON_TOKEN secret is missing, it exits cleanly. | |
| """ | |
| import json | |
| import os | |
| TOKEN_ENV_VAR = "HF_BUILD_SMALL_HACKATHON_TOKEN" | |
| DEFAULT_SPACE_ID = "byte-vortex/Myco" | |
| IGNORE_PATTERNS_TEXT = """ | |
| .git/* | |
| .github/* | |
| __pycache__/* | |
| **/__pycache__/* | |
| *.pyc | |
| .gradio/* | |
| .cache/* | |
| models/downloads/* | |
| models/**/*.gguf | |
| models/**/*.bin | |
| models/**/*.safetensors | |
| """ | |
| def get_ignore_patterns(): | |
| """Return upload ignore patterns as a list for huggingface_hub.""" | |
| return [str(pattern) for pattern in IGNORE_PATTERNS_TEXT.split()] | |
| def get_hf_token(): | |
| """Return the optional Hugging Face deploy token.""" | |
| return os.environ.get(TOKEN_ENV_VAR, "").strip() | |
| def get_space_id(): | |
| """Return the target Hugging Face Space id.""" | |
| return os.environ.get("HF_SPACE_ID", DEFAULT_SPACE_ID).strip() or DEFAULT_SPACE_ID | |
| def upload_space(token, repo_id): | |
| """Upload the repository folder to the configured Hugging Face Space.""" | |
| from huggingface_hub import HfApi | |
| HfApi().upload_folder( | |
| folder_path=".", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| token=token, | |
| ignore_patterns=get_ignore_patterns(), | |
| commit_message="Deploy Myco from CI", | |
| ) | |
| def main(): | |
| """Deploy when a token is configured; otherwise skip without failing.""" | |
| token = get_hf_token() | |
| if not token: | |
| print(f"{TOKEN_ENV_VAR} is not configured; skipping Hugging Face Space deployment.") | |
| return | |
| repo_id = get_space_id() | |
| for attempt in range(2): | |
| try: | |
| upload_space(token, repo_id) | |
| except json.JSONDecodeError as error: | |
| if attempt == 0: | |
| print("Hugging Face metadata validation returned non-JSON; retrying once.") | |
| continue | |
| print(f"Hugging Face metadata validation returned non-JSON again; skipping CI deploy: {error}") | |
| return | |
| print(f"Deployed Myco to https://huggingface.co/spaces/{repo_id}") | |
| return | |
| if __name__ == "__main__": | |
| main() | |