Download code/scripts/upload_runtime_archive.py from jisue/robottt-pi05-base-comparison: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/jisue/robottt-pi05-base-comparison/resolve/main/code/scripts/upload_runtime_archive.py
- Command line
-
hf download hf://jisue/robottt-pi05-base-comparison/code/scripts/upload_runtime_archive.py
-
curl -L -o upload_runtime_archive.py https://huggingface.co/jisue/robottt-pi05-base-comparison/resolve/main/code/scripts/upload_runtime_archive.py
2.05 kB
| """Upload the completed runtime archive without blocking checkpoint backups.""" | |
| import json,pathlib,time | |
| from datetime import datetime,timezone | |
| from huggingface_hub import HfApi,CommitOperationAdd | |
| root=pathlib.Path(__file__).resolve().parents[1];local=root/'.release_local' | |
| config=json.loads((local/'hf-backup.json').read_text());token=pathlib.Path(config['token_file']).read_text().strip() | |
| archive=local/'runtime-env.tar.gz';metadata=local/'runtime-archive.json';status=local/'hf-runtime-backup-status.json' | |
| try: | |
| deadline=time.monotonic()+3600 | |
| while not (archive.exists() and metadata.exists()): | |
| if time.monotonic()>deadline:raise TimeoutError('Runtime archive did not finish') | |
| time.sleep(10) | |
| status.write_text(json.dumps(dict(state='uploading',bytes=archive.stat().st_size,updated_utc=datetime.now(timezone.utc).isoformat()),indent=2)) | |
| operations=[ | |
| CommitOperationAdd(path_in_repo='environment/runtime-env.tar.gz',path_or_fileobj=str(archive)), | |
| CommitOperationAdd(path_in_repo='environment/runtime-archive.json',path_or_fileobj=str(metadata))] | |
| support=local/'runtime-support.tar.gz' | |
| if support.exists(): | |
| operations.extend([CommitOperationAdd(path_in_repo='environment/runtime-support.tar.gz',path_or_fileobj=str(support)),CommitOperationAdd(path_in_repo='environment/runtime-support.json',path_or_fileobj=str(local/'runtime-support.json'))]) | |
| commit=HfApi(token=token).create_commit(repo_id=config['repo_id'],repo_type='model',commit_message='Back up the exact runtime as inode-efficient archives',operations=operations) | |
| status.write_text(json.dumps(dict(state='uploaded',commit_oid=commit.oid,bytes=archive.stat().st_size,includes_python_and_renderer_support=support.exists(),updated_utc=datetime.now(timezone.utc).isoformat()),indent=2)) | |
| except Exception as error: | |
| status.write_text(json.dumps(dict(state='failed',error=(type(error).__name__+': '+str(error)).replace(token,'[redacted]'),updated_utc=datetime.now(timezone.utc).isoformat()),indent=2));raise SystemExit(1) | |