Spaces:
Running
Running
File size: 3,283 Bytes
057a205 5ec889d 057a205 | 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #!/usr/bin/env python3
"""
Deploy SPHEREx Data Explorer to Hugging Face Spaces (or update Dataset)
without git clone or external git CLI dependencies.
Uses the huggingface_hub Python library and your existing authenticated session.
"""
import argparse
import os
import sys
from huggingface_hub import HfApi, get_token
IGNORE_PATTERNS = [
".git/*",
".git",
".gitignore",
".dockerignore",
".pytest_cache/*",
".pytest_cache",
"__pycache__/*",
"__pycache__",
"*.pyc",
"*.fits",
"*.fits.gz",
"*.tar",
"*.zip",
"spherex_data/*",
"spherex_data",
"hips_cache/*",
"hips_cache",
"cache_cutouts/*",
"cache_cutouts",
"cache_remote/*",
"cache_remote",
"cache_previews/*",
"cache_previews",
"catalog_output/*",
"catalog_output",
".agents/*",
".agents",
"huggingface-space/*",
"huggingface-space",
"*.bak",
"index_prev_landing.html",
"downloaded_index_1.html",
]
def main():
parser = argparse.ArgumentParser(description="Deploy SPHEREx Explorer to Hugging Face")
parser.add_argument("--space-name", default="spherex-projects", help="Space repo name (e.g. spherex-projects or spherex-explorer)")
parser.add_argument("--target", choices=["space", "dataset", "both"], default="space", help="Target repository to push to")
parser.add_argument("--private", action="store_true", help="Create space as private (default is public)")
args = parser.parse_args()
token = get_token()
if not token:
print("[Error] No Hugging Face token found. Run 'huggingface-cli login' first.", file=sys.stderr)
sys.exit(1)
api = HfApi(token=token)
user_info = api.whoami()
username = user_info.get("name")
print(f"[Authenticated] Logged in as: {username}")
base_dir = os.path.dirname(os.path.abspath(__file__))
if args.target in ("space", "both"):
space_id = f"{username}/{args.space_name}"
print(f"\n[Step 1] Ensuring Space exists: {space_id} (Static SDK)...")
api.create_repo(
repo_id=space_id,
repo_type="space",
space_sdk="static",
private=args.private,
exist_ok=True,
)
print(f"[Step 2] Uploading application files to Space: {space_id}...")
api.upload_folder(
folder_path=base_dir,
repo_id=space_id,
repo_type="space",
ignore_patterns=IGNORE_PATTERNS,
commit_message="Deploy SPHEREx Data Explorer (Static)",
)
print(f"\n[Success] Space deployed! View build and app at:")
print(f" https://huggingface.co/spaces/{space_id}")
if args.target in ("dataset", "both"):
dataset_id = f"{username}/spherex-projects"
print(f"\n[Step 3] Uploading current application files to Dataset: {dataset_id}...")
api.upload_folder(
folder_path=base_dir,
repo_id=dataset_id,
repo_type="dataset",
ignore_patterns=IGNORE_PATTERNS,
commit_message="Update SPHEREx application source files",
)
print(f"\n[Success] Dataset files updated at:")
print(f" https://huggingface.co/datasets/{dataset_id}")
if __name__ == "__main__":
main()
|