Download src/build_assets.py from HelloSun/dosllm: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/HelloSun/dosllm/resolve/main/src/build_assets.py
- Command line
-
hf download hf://spaces/HelloSun/dosllm/src/build_assets.py
-
curl -L -o build_assets.py https://huggingface.co/spaces/HelloSun/dosllm/resolve/main/src/build_assets.py
1.04 kB
| #!/usr/bin/env python3 | |
| """Pack the v86 runtime pieces and the DOS floppy as gzip+base64 JS in dist/. | |
| HF static Spaces serve binary files through a CORS-less redirect, but text files | |
| are served directly, so everything binary travels as base64 text.""" | |
| import base64, gzip, json, os, shutil | |
| from pathlib import Path | |
| root = Path(__file__).resolve().parent.parent | |
| deps = Path(os.environ.get("DEPS", root / "deps")) | |
| dist = root / "dist"; dist.mkdir(exist_ok=True) | |
| parts = {"wasm": deps / "v86/v86.wasm", "bios": deps / "v86/seabios.bin", | |
| "vga": deps / "v86/vgabios.bin", "img": root / "build/dosllm.img"} | |
| assets = {} | |
| for key, path in parts.items(): | |
| raw = path.read_bytes(); z = gzip.compress(raw, 9, mtime=0) | |
| assets[key] = base64.b64encode(z).decode() | |
| print(f"{key:5} {len(raw):>8} -> gzip {len(z):>8} -> base64 {len(assets[key]):>8}") | |
| (dist / "assets.b64.js").write_text("window.DOSLLM_ASSETS=" + json.dumps(assets) + ";\n") | |
| shutil.copy(deps / "v86/libv86.js", dist / "libv86.js") | |
| print("wrote", dist / "assets.b64.js") | |