Download scripts/publish_space.py from StarAtNyte1/beam-boot: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/scripts/publish_space.py
- Command line
-
hf download hf://StarAtNyte1/beam-boot/scripts/publish_space.py
-
curl -L -o publish_space.py https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/scripts/publish_space.py
1.49 kB
| """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') | |
| 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 | |
| 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) | |