Download setup.py from Johnny5b/portable-ai-runner: direct link, hf CLI and curl.
- Browser
- Download file 4.38 kB
-
https://huggingface.co/datasets/Johnny5b/portable-ai-runner/resolve/main/setup.py
- Command line
-
hf download hf://datasets/Johnny5b/portable-ai-runner/setup.py
-
curl -L -o setup.py https://huggingface.co/datasets/Johnny5b/portable-ai-runner/resolve/main/setup.py
4.38 kB
| # Portable AI Runner - one-time setup v4 (resumable + sha256-verified GGUF fetch) | |
| # Online ONCE: pip install requests | |
| # python setup.py -> Qwen3-0.6B GGUF (639 MB) + wllama engine assets | |
| # python setup.py --model ornith -> also Ornith-1.5-9B GGUF (5.8 GB, server-tier file) | |
| # Offline forever after. GGUF only - no banned engines (owner directive 2026-09-18). | |
| import hashlib | |
| import io | |
| import json | |
| import os | |
| import sys | |
| import tarfile | |
| import requests | |
| WLLAMA_VERSION = "3.6.1" | |
| GGUF_DIR = os.path.join("models", "gguf") | |
| # sha256 = Hub LFS oids, verified 2026-09-18 (models/weights-manifest.json) | |
| PINNED = { | |
| "Qwen3-0.6B-Q8_0.gguf": ( | |
| "Qwen/Qwen3-0.6B-GGUF", 639446688, | |
| "9465e63a22add5354d9bb4b99e90117043c7124007664907259bd16d043bb031", | |
| ), | |
| "Ornith-1.5-9B-Q4_K_M.gguf": ( | |
| "ornith-ai/Ornith-1.5-9B-GGUF", 5780090816, | |
| "70c112196e0b7023803c9762752e46d29e612a92c83f995bc3ba1ceb07e8fab6", | |
| ), | |
| } | |
| def vendor_wllama(): | |
| os.makedirs(os.path.join("vendor", "wllama", "esm"), exist_ok=True) | |
| print("downloading wllama engine assets (llama.cpp WASM) ...") | |
| tgz = requests.get( | |
| "https://registry.npmjs.org/@wllama/wllama/-/wllama-" + WLLAMA_VERSION + ".tgz", | |
| timeout=120).content | |
| with tarfile.open(fileobj=io.BytesIO(tgz), mode="r:gz") as t: | |
| for member in t.getmembers(): | |
| if member.name.startswith("package/esm/"): | |
| dest = os.path.join("vendor/wllama/esm", | |
| os.path.relpath(member.name, "package/esm")) | |
| if member.isdir(): | |
| os.makedirs(dest, exist_ok=True) | |
| continue | |
| os.makedirs(os.path.dirname(dest), exist_ok=True) | |
| with open(dest, "wb") as f: | |
| f.write(t.extractfile(member).read()) | |
| wasm = os.path.join("vendor", "wllama", "esm", "wasm", "wllama.wasm") | |
| assert os.path.isfile(wasm) and os.path.getsize(wasm) > 1_000_000, \ | |
| "wllama.wasm missing after vendoring" | |
| print(" ok: vendored, esm/wasm/wllama.wasm present") | |
| def fetch_gguf(repo, fname, size, sha_expected): | |
| url = "https://huggingface.co/" + repo + "/resolve/main/" + fname | |
| dest = os.path.join(GGUF_DIR, fname) | |
| pos = os.path.getsize(dest) if os.path.exists(dest) else 0 | |
| if pos == size: | |
| print(" already complete:", dest) | |
| else: | |
| if pos: | |
| print(" resuming from %.2f GB ..." % (pos / 1e9)) | |
| headers = {"Range": "bytes=%d-" % pos} if pos else {} | |
| r = requests.get(url, stream=True, timeout=600, headers=headers) | |
| if pos and r.status_code != 206: | |
| print(" server does not support resume - restarting") | |
| pos, r = 0, requests.get(url, stream=True, timeout=600) | |
| r.raise_for_status() | |
| with open(dest, "ab" if pos else "wb") as f: | |
| for chunk in r.iter_content(1 << 22): | |
| f.write(chunk) | |
| print(" verifying sha256 ...") | |
| h = hashlib.sha256() | |
| with open(dest, "rb") as f: | |
| for chunk in iter(lambda: f.read(1 << 22), b""): | |
| h.update(chunk) | |
| if h.hexdigest() != sha_expected: | |
| os.remove(dest) | |
| raise SystemExit("SHA256 MISMATCH for " + fname + | |
| " - corrupt/partial download removed. Re-run setup.py.") | |
| print(" ok: " + fname + " sha256 verified") | |
| def main(): | |
| args = [a.lower() for a in sys.argv[1:]] | |
| want_ornith = any("ornith" in a for a in args) | |
| os.makedirs(GGUF_DIR, exist_ok=True) | |
| vendor_wllama() | |
| picks = [] | |
| if want_ornith: | |
| picks.append("Ornith-1.5-9B-Q4_K_M.gguf") | |
| picks.append("Qwen3-0.6B-Q8_0.gguf") | |
| entries = [] | |
| for fname in picks: | |
| repo, size, sha = PINNED[fname] | |
| print("downloading " + repo + "/" + fname + " (%.2f GB) ..." % (size / 1e9)) | |
| fetch_gguf(repo, fname, size, sha) | |
| entries.append({"name": fname.replace(".gguf", ""), | |
| "url": "./models/gguf/" + fname, | |
| "size_gb": round(size / 1e9, 2), "sha256": sha}) | |
| manifest = {"engine": "wllama (llama.cpp WASM)", "models": entries} | |
| with open(os.path.join("models", "models.json"), "w") as f: | |
| json.dump(manifest, f, indent=2) | |
| print("done. Launch serve.py and open http://localhost:8080 - fully offline from here on.") | |
| if __name__ == "__main__": | |
| main() | |