"""Portable server launcher; key remains local and is never printed.""" import os, secrets, sys from pathlib import Path ROOT=Path(__file__).resolve().parent private=ROOT/'runtime/workspace' private.mkdir(mode=0o700,exist_ok=True) key=private/'local-api.key' if not key.exists(): fd=os.open(key,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o600) with os.fdopen(fd,'w') as stream:stream.write(secrets.token_urlsafe(36)+'\n') os.environ.setdefault('HF_HOME',str(ROOT/'.hf-cache')) os.environ['HF_HUB_OFFLINE']='1' os.execv(sys.executable,[sys.executable,str(ROOT/'runtime/local_model_api.py'),'--model',str(ROOT),'--host',os.environ.get('LAYA_HOST','0.0.0.0'),'--port',os.environ.get('LAYA_PORT','8765'),'--key-file',str(key),'--idle-seconds','120',*sys.argv[1:]])