"""Reproducible native CPU environment; public code only, no private voice download.""" import argparse,hashlib,json,os,subprocess,tarfile,urllib.request,zipfile from pathlib import Path PYTHON_URL='https://github.com/astral-sh/python-build-standalone/releases/download/20261026/cpython-3.11.18%2B20261026-x86_64-unknown-linux-gnu-install_only.tar.gz' PYTHON_SHA='a87ee63646c8f8438b7af3954b2135ed2af91d033c631f12a8f20af903046d06' UV_URL='https://files.pythonhosted.org/packages/5c/43/0688ff5142934238f2812e348f4a24e09b57d48bfb38dd8f850325a0d9de/uv-0.13.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl' UV_SHA='22759b8895e1103578de6fb4cd27e94b4399d021023378d29f01333717751fba' def download(url,path,expected): with urllib.request.urlopen(url,timeout=120) as source,path.open('wb') as out: while block:=source.read(1024*1024):out.write(block) with path.open('rb') as f:assert hashlib.file_digest(f,'sha256').hexdigest()==expected,'Public download hash mismatch' def install(root): root=Path(root).resolve();root.mkdir(parents=True,exist_ok=True,mode=0o700) archive=root/'python.tar.gz';download(PYTHON_URL,archive,PYTHON_SHA) with tarfile.open(archive) as t:t.extractall(root,filter='data') archive.unlink() wheel=root/'uv.whl';download(UV_URL,wheel,UV_SHA) with zipfile.ZipFile(wheel) as z: names=[n for n in z.namelist() if n.endswith('/uv')];assert len(names)==1 uv=root/'uv';uv.write_bytes(z.read(names[0]));uv.chmod(0o700) wheel.unlink() (root/'tmp').mkdir(mode=0o700,exist_ok=True) # phonemizer copies its shared library into TMPDIR. The production /tmp is # intentionally noexec; use this runtime's own private executable data mount. env=dict(os.environ,TMPDIR=str(root/'tmp'),CUDA_VISIBLE_DEVICES='',UV_NO_CONFIG='1',UV_CACHE_DIR=str(root/'cache'),UV_PYTHON_DOWNLOADS='never',GIT_TERMINAL_PROMPT='0') def run(*args):subprocess.run([str(x) for x in args],env=env,check=True) py=root/'venv/bin/python' run(uv,'venv','--python',root/'python/bin/python3.11',root/'venv') run(uv,'pip','install','--python',py,'--index-url','https://download.pytorch.org/whl/cpu','torch==2.6.0+cpu') run(uv,'pip','install','--python',py,'--extra-index-url','https://download.pytorch.org/whl/cpu', '--index-strategy','unsafe-best-match','-r',Path(__file__).with_name('requirements.lock')) run(uv,'pip','check','--python',py) run(py,'-c','import torch;from kokoro import KModel,KPipeline;from misaki.de import DEG2P;assert torch.version.cuda is None;assert DEG2P()("Die Stimme ist bereit.")[0]') (root/'requirements-resolved.txt').write_text(subprocess.check_output([str(uv),'pip','freeze','--python',str(py)],env=env,text=True)) # Wheel/Git build caches are not needed by offline inference. import shutil shutil.rmtree(root/'cache',ignore_errors=True) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--root',required=True,type=Path);a=p.parse_args();install(a.root)