Files
Athena-Deck/deploy/import_applio.py
T
Mikei386 06cacafbad Add native Applio RVC and preserve the custom studio UI
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.
2026-10-05 10:02:07 +02:00

47 lines
3.2 KiB
Python

"""Copy old private voices/training data without fabricating public sources.
Never changes endpoint activation or running services. Originals remain intact.
"""
import hashlib,json,os,shutil,time,uuid
from pathlib import Path
def run(old,state):
old=Path(old);state=Path(state);target=state/'applio-data';target.mkdir(exist_ok=True)
manifest=[]
for source_name,dest_name in [('logs','logs'),('datasets','datasets')]:
source=old/source_name;dest=target/dest_name
if not dest.exists():shutil.copytree(source,dest,symlinks=False)
for file in source.rglob('*'):
if not file.is_file():continue
rel=file.relative_to(source);copy=dest/rel
if file.is_symlink():raise ValueError('Alte Applio-Daten enthalten einen Symlink: '+str(rel))
def digest(p):
h=hashlib.sha256()
with p.open('rb') as stream:
while chunk:=stream.read(4*1024**2):h.update(chunk)
return h.hexdigest()
sha=digest(file)
if not copy.is_file() or copy.stat().st_size!=file.stat().st_size or digest(copy)!=sha:raise ValueError('Kopie unvollständig: '+str(rel))
manifest.append(dict(file=dest_name+'/'+str(rel),sha256=sha,size=copy.stat().st_size,source='Eigene Applio-Daten des alten Routers'))
print('Verified data:',dest_name,flush=True)
(target/'migration-manifest.json').write_text(json.dumps(manifest,ensure_ascii=False));library=state/'models';entries=[]
for pth in (target/'logs').rglob('*.pth'):
if pth.name.startswith(('G_','D_')):continue
relative=pth.relative_to(target/'logs').as_posix();sha=hashlib.sha256(pth.read_bytes()).hexdigest();revision=sha;repo='local/mikes-applio';ident=hashlib.sha256((repo+revision+relative).encode()).hexdigest();folder=library/ident;folder.mkdir(exist_ok=True)
if not (folder/'model.pth').exists():shutil.copyfile(pth,folder/'model.pth')
entry=dict(repo=repo,revision=revision,file=relative,size=pth.stat().st_size,sha256=sha,kind='voice',downloaded_at=time.time(),state='downloaded',runtime_ready=False,runtime_metadata=dict(architecture='rvc',tags=['private-trained-voice']),source_note='Lokales Stimmgewicht aus Mikes Applio. Kein verifizierter öffentlicher Downloadlink; separat sichern.')
(folder/'entry.json').write_text(json.dumps(entry));entries.append((pth.stem,ident))
path=state/'profiles.json';profiles=json.loads(path.read_text())
if entries and not any(p.get('api_id')=='applio-rvc' for p in profiles):
chosen=next((x for x in entries if x[0]=='Anna Broadcast Excited & Journalistic'),entries[0])
profiles.append(dict(id=uuid.uuid4().hex,revision=1,name='Applio RVC',api_id='applio-rvc',api_aliases=[],kind='voice',model_id=chosen[1],parameters={},components={},presets=[],prompt_enhancer=None,updated_at=time.time()))
# Written to a pending file. Apply only after the old server is stopped.
(state/'applio-profile-pending.json').write_text(json.dumps(profiles[-1]))
for p in [target,*target.rglob('*'),*(library/ident for _,ident in entries)]:
if p.is_symlink():raise ValueError('Unerwarteter Symlink')
os.chown(p,65534,65534)
for _,ident in entries:
for p in (library/ident).iterdir():os.chown(p,65534,65534)
print('Complete:',len(entries),'voice weights; inactive profile prepared',flush=True)
if __name__=='__main__':
import sys;run(*sys.argv[1:])