Spaces:
Sleeping

Myco / scripts /deploy_space.py
byte-vortex's picture
Deploy Myco from CI
9fa751e verified
Raw History Blame
1.59 kB
"""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 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 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
from huggingface_hub import HfApi
repo_id = get_space_id()
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",
)
print(f"Deployed Myco to https://huggingface.co/spaces/{repo_id}")
if __name__ == "__main__":
main()