retroenv-rollouts / build.py
AdithyaSK's picture
AdithyaSK HF Staff
Load tasks with a script tag: fetch is blocked inside the Space iframe
db2825f verified
Raw History Blame Contribute Delete
838 Bytes
"""Inline the three startup files into index.html so the first paint needs no fetch."""
import io, json, pathlib
root = pathlib.Path(__file__).parent
src = (root / 'index.src.html').read_text(encoding='utf-8')
blocks = []
for el, name in (('d-index', 'index.json'), ('d-checkpoints', 'checkpoints.json'), ('d-frontier', 'frontier.json')):
data = json.loads((root / name).read_text(encoding='utf-8'))
# </script> inside JSON would close the tag early
text = json.dumps(data, separators=(',', ':')).replace('</', '<\\/')
blocks.append(f'<script id="{el}" type="application/json">{text}</script>')
out = src.replace('<!--INLINE-DATA-->', '\n'.join(blocks))
assert '<!--INLINE-DATA-->' not in out
(root / 'index.html').write_text(out, encoding='utf-8')
print(f'index.html {len(out)/1e6:.2f} MB (inlined {len(blocks)} files)')