Pin Applio 3.6.5 and verified basis assets, migrate private voice provenance, and coordinate conversion/live/training with Deck GPU leases. Prepare an inactive voice profile and a restricted studio container. Move CUDA and Torch caches out of the small temporary filesystem to prevent OmniVoice reference failures. Package app updates from the explicit allowlist in one Docker layer.
65 lines
5.6 KiB
Python
65 lines
5.6 KiB
Python
"""Pinned Applio runtime, isolated from other models; setup never uses a GPU."""
|
|
import json,os,shutil,sys,time,urllib.request,hashlib
|
|
from pathlib import Path
|
|
from ltx_original_runtime import LTXOriginalRuntime
|
|
VERSION='3.6.5'
|
|
REVISION='55fe0b976a6990bb75261c32ccecf6bfca3198f1'
|
|
ASSET_REVISION='70ed563897504c756ec94067c12c902c4fd42025'
|
|
ASSETS={**{'Resources/pretrained_v2/f0'+x+rate+'.pth':'pretraineds/hifi-gan/f0'+x+rate+'.pth' for x in ('G','D') for rate in ('32k','40k','48k')},**{'Resources/refinegan/f0'+x+rate+'.pth':'pretraineds/refinegan/f0'+x+rate+'.pth' for x in ('G','D') for rate in ('24k','32k')},'Resources/predictors/rmvpe.pt':'predictors/rmvpe.pt','Resources/predictors/fcpe.pt':'predictors/fcpe.pt','Resources/embedders/contentvec/pytorch_model.bin':'embedders/contentvec/pytorch_model.bin','Resources/embedders/contentvec/config.json':'embedders/contentvec/config.json'}
|
|
class ApplioRuntime(LTXOriginalRuntime):
|
|
name='Applio / RVC'
|
|
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):
|
|
b=self.root/ident
|
|
if (b/'ready').read_text().strip()==REVISION:return b/'python/bin/python',b/'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/'core.py').is_file(),version=VERSION,revision=REVISION,job=dict(self.job) if self.job else None,required_disk_gib=25,shared_cuda=False,worker_available=True,origin='IAHispano/Applio',message='Stimmumwandlung, Live und eigenes RVC-Training. Einrichtung lädt die offiziellen Basisgewichte; eigene Stimmen bleiben getrennt.')
|
|
def _run(self):
|
|
b=self.root/self.job['id'];state='failed';phase='Applio-Einrichtung fehlgeschlagen.'
|
|
try:
|
|
b.mkdir(mode=0o700);tmp=b/'tmp';tmp.mkdir();source=b/'source'
|
|
env=dict(os.environ,TMPDIR=str(tmp),PIP_NO_INPUT='1',PIP_DISABLE_PIP_VERSION_CHECK='1',CUDA_VISIBLE_DEVICES='',GIT_TERMINAL_PROMPT='0')
|
|
self._phase('Applio '+VERSION+' aus offizieller Quelle beziehen')
|
|
for args in (['git','init',source],['git','-C',source,'fetch','--depth','1','https://github.com/IAHispano/Applio.git',REVISION],['git','-C',source,'checkout','--detach','FETCH_HEAD']):self._command(args,env)
|
|
live=source/'rvc/realtime/core.py'
|
|
text=live.read_text();old='self.resample_out(audio_model * vol_t)'
|
|
if text.count(old)!=1:raise ValueError('Live-Patch passt nicht zur gepinnten Applio-Version.')
|
|
live.write_text(text.replace(old,'self.resample_out(audio_model)'))
|
|
shared=self.image_runtime.paths()[0] if self.image_runtime else Path('/missing')
|
|
self._command([shared if shared.is_file() else sys.executable,'-m','venv',b/'python'],env);python=b/'python/bin/python'
|
|
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'],env)
|
|
self._phase('Eigene Applio-Abhängigkeiten und unsere Oberfläche installieren')
|
|
requirements=b/'requirements.txt';requirements.write_text('\n'.join(x for x in (source/'requirements.txt').read_text().splitlines() if not x.startswith(('torch==','torchaudio==')))+'\n')
|
|
self._command([python,'-m','pip','install','--no-cache-dir','-c',Path(__file__).parent/'deploy/applio-requirements.lock','-r',requirements,'fastapi','uvicorn','python-multipart','pydantic-settings','aiofiles','httpx','websockets'],env)
|
|
self._phase('Offizielle Basisgewichte mit Quellnachweis beziehen')
|
|
with urllib.request.urlopen('https://huggingface.co/api/models/IAHispano/Applio/revision/'+ASSET_REVISION+'?blobs=true',timeout=30) as r:meta=json.load(r)
|
|
revision=meta['sha']
|
|
if revision!=ASSET_REVISION:raise ValueError('Offizielle Basisgewicht-Version stimmt nicht mit dem Rezept überein.')
|
|
files={f['rfilename']:f for f in meta['siblings']};manifest=[]
|
|
for name,target in ASSETS.items():
|
|
if self.cancel.is_set():raise InterruptedError()
|
|
item=files[name];dest=source/'rvc/models'/target;dest.parent.mkdir(parents=True,exist_ok=True);digest=hashlib.sha256()
|
|
with urllib.request.urlopen('https://huggingface.co/IAHispano/Applio/resolve/'+revision+'/'+name,timeout=60) as response,dest.open('wb') as output:
|
|
while chunk:=response.read(4*1024**2):
|
|
if self.cancel.is_set():raise InterruptedError()
|
|
output.write(chunk);digest.update(chunk)
|
|
if dest.stat().st_size!=item['size']:raise ValueError('Basisgewicht hat falsche Größe: '+name)
|
|
if item.get('lfs') and digest.hexdigest()!=item['lfs']['sha256']:raise ValueError('Basisgewicht-Prüfsumme falsch: '+name)
|
|
manifest.append(dict(repo='IAHispano/Applio',revision=revision,file=name,target=target,sha256=digest.hexdigest(),size=dest.stat().st_size))
|
|
(b/'asset-sources.json').write_text(json.dumps(manifest))
|
|
self._phase('Imports und Paketkonsistenz prüfen')
|
|
self._command([python,'-m','pip','check'],env)
|
|
self._command([python,'-c','import torch,transformers,faiss,librosa,soundfile,fastapi,uvicorn; assert torch.version.cuda'],env)
|
|
self._command([python,'-m','pip','freeze'],env)
|
|
(b/'ready').write_text(REVISION);marker=self.root/'active.tmp';marker.write_text(json.dumps(dict(id=b.name)));marker.replace(self.root/'active.json');state='complete';phase='Applio 3.6.5 installiert · kein Stimmprofil aktiviert'
|
|
except InterruptedError:state='cancelled';phase='Applio-Einrichtung abgebrochen.'
|
|
except Exception as exc:phase=str(exc)
|
|
finally:
|
|
if state!='complete':shutil.rmtree(b,ignore_errors=True)
|
|
with self.lock:self.process=None;self.job.update(state=state,phase=phase,finished_at=time.time());self._save()
|