Files
Athena-Deck/qwen_native_runtime.py

59 lines
3.4 KiB
Python

"""Pinned native Qwen3-TTS CPU runtime; explicit Q8/Q4 recipes in the library."""
import json,os,shutil,sys
from pathlib import Path
from ltx_original_runtime import LTXOriginalRuntime
VERSION='0.4.2'
REPO='Serveurperso/Qwen3-TTS-GGUF'
REVISION='b7ee2e8c7459c3bea99da23e3d178125a7d1713c'
MODEL_FILE='qwen-talker-0.6b-base-Q8_0.gguf'
MODEL_FILES={
MODEL_FILE:dict(quant='Q8',sha256='d54dbaf10591421fa764ed630d764efa717ae40cd959bd48c66d4eb1af226426'),
'qwen-talker-0.6b-base-Q4_K_M.gguf':dict(quant='Q4',sha256='4b468ec7b1f62b90ef4ca316c0aa57deadfd54b2cf9651703ea753cedaf04226'),
}
CODEC_FILE='qwen-tokenizer-12hz-Q8_0.gguf'
COMPONENTS={'codec':dict(label='Qwen Sprach-Codec · Q8_0',revision=REVISION,files=[CODEC_FILE])}
def supported(model):
return bool(model and model.get('kind')=='audio' and model.get('repo')==REPO and model.get('revision')==REVISION and model.get('file') in MODEL_FILES)
def model_quant(model):
if not supported(model):raise ValueError('Unbekanntes natives Qwen-CPU-Modell.')
return MODEL_FILES[model['file']]['quant']
class QwenNativeRuntime(LTXOriginalRuntime):
name='Qwen3-TTS 0.6B Q8/Q4 · CPU'
def __init__(self,root):super().__init__(root,None)
def paths(self):
try:
ident=json.loads((self.root/'active.json').read_text())['id']
if len(ident)==32 and all(c in '0123456789abcdef' for c in ident):
base=self.root/ident
if (base/'ready').read_text().strip()==VERSION:return base/'python/bin/python',base
except (OSError,ValueError,KeyError,TypeError):pass
return self.root/'missing-python',self.root/'missing-runtime'
def status(self):
python,base=self.paths()
return dict(installed=python.is_file() and (base/'ready').is_file(),version=VERSION,device='cpu',required_disk_gib=3,job=dict(self.job) if self.job else None,speakers=['default','Anna'],languages=['German'],origin='https://github.com/KoljaB/RealtimeTTS',generation_threads=4,codec_threads=4,stream_frames=2)
def _run(self):
base=self.root/self.job['id'];state='failed';phase='Native Qwen-CPU-Einrichtung fehlgeschlagen.'
try:
base.mkdir(mode=0o700)
env={k:v for k,v in os.environ.items() if not k.startswith(('HF_','DECK_','LLAMA_','OPENAI_'))}
env.update(PIP_NO_INPUT='1',PIP_DISABLE_PIP_VERSION_CHECK='1',CUDA_VISIBLE_DEVICES='',HF_HUB_DISABLE_IMPLICIT_TOKEN='1')
self._phase('Eigene native CPU-Python-Umgebung erstellen');self._command([sys.executable,'-m','venv',base/'python'],env)
python=base/'python/bin/python'
self._phase('Gepinnte Qwen-CPU-Laufzeit installieren · ohne PyTorch oder CUDA')
self._command([python,'-m','pip','install','--only-binary=:all:','-r',Path(__file__).parent/'deploy/qwen-native-requirements.lock'],env)
self._command([python,'-m','pip','check'],env)
self._command([python,'-c','import qwentts_cpp_cpu as q;assert q.CPU_ONLY is True;assert q.QT_ABI_VERSION==5'],env)
if self.cancel.is_set():raise InterruptedError()
(base/'ready').write_text(VERSION)
temp=self.root/'active.tmp';temp.write_text(json.dumps({'id':base.name}));temp.replace(self.root/'active.json')
state='complete';phase='Native Qwen-CPU-Laufzeit bereit · Q8- oder Q4-Modell und Q8-Sprach-Codec im Profil zuordnen'
except InterruptedError:state='cancelled';phase='Einrichtung abgebrochen.'
except Exception as exc:phase=str(exc)
finally:
if state!='complete':shutil.rmtree(base,ignore_errors=True)
with self.lock:self.process=None;self.job.update(state=state,phase=phase);self._save()