"""Publish the prepared Space using the user's Modal-held HF write token. The token is returned to this local process in memory only; it is never printed or saved. Existing repositories are never overwritten by this script. """ import os from pathlib import Path import modal app = modal.App('beamboot-publish') @app.function(image=modal.Image.debian_slim(python_version='3.12'), secrets=[modal.Secret.from_name('steerability-submission-write')]) def get_write_token(): token = os.environ.get('HUGGINGFACE_TOKEN') or os.environ.get('HF_TOKEN') if not token: raise RuntimeError('No HF write token in configured secret') return token @app.local_entrypoint() def main(): from huggingface_hub import HfApi token = get_write_token.remote() api = HfApi(token=token) name = api.whoami()['name'] repo_id = f'{name}/beam-boot' if not api.repo_exists(repo_id=repo_id, repo_type='space'): api.create_repo(repo_id=repo_id, repo_type='space', space_sdk='static', private=False) print(f'Uploading to Space created for this task: https://huggingface.co/spaces/{repo_id}', flush=True) api.upload_folder(repo_id=repo_id, repo_type='space', folder_path=str(Path('static-space').resolve()), commit_message='Add Super Beam: Beam plays a game that runs inside Beam', ignore_patterns=['**/__pycache__/**', '**/*.pyc']) print(f'Uploaded files: https://huggingface.co/spaces/{repo_id}', flush=True)