43 lines
3.0 KiB
Python
43 lines
3.0 KiB
Python
"""Pinned SoulX SVC runtime; installation and restore do not use a GPU."""
|
|
import hashlib,json,os,sys,time
|
|
from pathlib import Path
|
|
from ltx_original_runtime import LTXOriginalRuntime
|
|
REPO='Soul-AILab/SoulX-Singer'
|
|
REVISION='81aeb3ae772c70093c3de74dc23c92d983801ae4'
|
|
ASSETS=json.loads((Path(__file__).parent/'deploy/soulx-singer-svc/assets.json').read_text())
|
|
MAIN=next(a for a in ASSETS if a['filename']=='model-svc.pt')
|
|
MODEL_REVISION=MAIN['revision']
|
|
RECIPE_HASH=hashlib.sha256(json.dumps(ASSETS,sort_keys=True).encode()).hexdigest()
|
|
class SoulXSingerRuntime(LTXOriginalRuntime):
|
|
name='SoulX-Singer'
|
|
def paths(self):
|
|
try:
|
|
ready=json.loads((self.root/'ready.json').read_text())
|
|
if ready['source_revision']==REVISION and (self.root/'ui-ready').is_file():return self.root/'python/bin/python',self.root/'source'
|
|
except (OSError,ValueError,KeyError):pass
|
|
return self.root/'missing-python',self.root/'missing-source'
|
|
def status(self):
|
|
python,source=self.paths()
|
|
return dict(installed=python.is_file() and (source/'cli/inference_svc.py').is_file(),revision=REVISION,model_revision=MODEL_REVISION,recipe_hash=RECIPE_HASH,job=dict(self.job) if self.job else None,required_disk_gib=20,origin=REPO,worker_available=True,message='Vorhandenen Gesang mit einer Referenzstimme umwandeln; 24 kHz, kein Training. Saubere Gesangsreferenz empfohlen.')
|
|
def ensure_library(self):
|
|
folder=self.root.parent/'models'/hashlib.sha256((REPO+MODEL_REVISION+MAIN['filename']).encode()).hexdigest();folder.mkdir(parents=True,exist_ok=True)
|
|
asset=self.root/'assets/soulx/model-svc.pt';target=folder/'model.pt';relative=os.path.relpath(asset,folder)
|
|
if target.is_symlink() and os.readlink(target)!=relative:raise ValueError('SoulX-Bibliothekslink zeigt auf fremde Datei.')
|
|
if not target.exists() and not target.is_symlink():target.symlink_to(relative)
|
|
if not target.is_symlink():raise ValueError('SoulX-Bibliotheksdatei ist kein verwalteter Link.')
|
|
(folder/'entry.json').write_text(json.dumps(dict(repo=REPO,revision=MODEL_REVISION,file=MAIN['filename'],kind='voice',size=MAIN['size'],sha256=MAIN['sha256'],upstream_hash_verified=True,downloaded_at=time.time(),runtime_metadata={'architecture':'soulx_singer'})))
|
|
return folder.name
|
|
def _run(self):
|
|
state='failed';phase='SoulX-Einrichtung fehlgeschlagen.'
|
|
try:
|
|
env=dict(os.environ,CUDA_VISIBLE_DEVICES='',OMP_NUM_THREADS='2',MKL_NUM_THREADS='2')
|
|
recipe=Path(__file__).parent/'deploy/soulx-singer-svc/prepare.py'
|
|
self._phase('SoulX-Gewichte und isolierte Laufzeit vorbereiten')
|
|
self._command([sys.executable,recipe,self.root],env)
|
|
self._command([self.root/'python/bin/python','-c','import gradio,uvicorn,fastapi;assert gradio.__version__=="5.49.1"'],env)
|
|
(self.root/'ui-ready').write_text(REVISION);self.ensure_library();state='complete';phase='SoulX-Singer vorbereitet'
|
|
except InterruptedError:state='cancelled';phase='SoulX-Installation abgebrochen.'
|
|
except Exception as exc:phase=str(exc)
|
|
finally:
|
|
with self.lock:self.process=None;self.job.update(state=state,phase=phase,finished_at=time.time());self._save()
|