"""Pinned SheetSage2/MERT transcription environment for the existing YuE2 UI.""" import hashlib,json,os,shutil,site,sys,urllib.request from pathlib import Path from ltx_original_runtime import LTXOriginalRuntime SOURCES=json.loads(Path(__file__).with_name('remix_sources.json').read_text()) VERSION='SheetSage2-eab522a + MERT-d8ba1c7' class RemixRuntime(LTXOriginalRuntime): name='YuE2 Audio Remix' def __init__(self,root,separator):super().__init__(root,None);self.separator=separator 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').is_file():return base/'python/bin/python',base/'models' except (OSError,ValueError,KeyError):pass return self.root/'missing-python',self.root/'missing-models' def status(self): python,models=self.paths() return dict(installed=python.is_file() and (models/'SheetSage2/model.safetensors').is_file() and (models/'MERT-v2-FullSong/model.safetensors').is_file(),version=VERSION,required_disk_gib=8,job=dict(self.job) if self.job else None,sources=SOURCES) def _run(self): base=self.root/self.job['id'];state='failed';phase='Remix-Einrichtung fehlgeschlagen.' try: base.mkdir(mode=0o700);models=base/'models';models.mkdir();python=base/'python/bin/python' self._phase('Remix · isolierte Python-Umgebung');self._command([sys.executable,'-m','venv',base/'python']) shared=self.separator.paths()[0] if shared.is_file(): from cuda_overlay import share_cuda share_cuda(python,base,shared,self._command) else:self._command([python,'-m','pip','install','--no-cache-dir','torch==2.11.0','torchaudio==2.11.0','--index-url','https://download.pytorch.org/whl/cu128']) self._phase('SheetSage2-Abhängigkeiten');self._command([python,'-m','pip','install','--no-cache-dir','transformers==4.45.2','huggingface-hub==0.36.0','safetensors==0.5.3','numpy==1.26.4','scipy==1.13.1','mir_eval==0.8.2','pretty_midi==0.2.10','mido==1.3.3','soundfile==0.13.1','setuptools==78.1.1','torch==2.11.0','torchaudio==2.11.0']) self._command([python,'-m','pip','check']) for recipe in SOURCES.values(): for item in recipe['files']: self._phase('Remix-Modellpaket: '+item['file']);dest=models/item['file'];dest.parent.mkdir(parents=True,exist_ok=True);h=hashlib.sha256();size=0 with urllib.request.urlopen(item['urls'][0],timeout=90) as response,dest.open('wb') as out: while chunk:=response.read(1024**2): if self.cancel.is_set():raise InterruptedError() size+=len(chunk) if size>4*1024**3:raise ValueError('Modellquelldatei zu groß.') h.update(chunk);out.write(chunk) if h.hexdigest()!=item['sha256']:raise ValueError('Prüfsumme stimmt nicht: '+item['file']) self._command([python,'-c','import torch,transformers,soundfile;assert torch.version.cuda;assert transformers.__version__=="4.45.2"']) (base/'ready').write_text(VERSION);tmp=self.root/'active.tmp';tmp.write_text(json.dumps({'id':base.name}));tmp.replace(self.root/'active.json') state='complete';phase='Audio Remix bereit · SheetSage2 und MERT installiert' except InterruptedError:state='cancelled';phase='Remix-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()