Spaces:
Running
Running
File size: 2,140 Bytes
98cbf67 4713899 78ceed6 4713899 4cc2f21 4713899 a6856e0 e877495 9fa751e e877495 a6856e0 231d560 a6856e0 231d560 78ceed6 a6856e0 4713899 a6856e0 78ceed6 4713899 | 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | """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()
|