51 lines
4.1 KiB
Python
51 lines
4.1 KiB
Python
"""Prepare Seed-VC without starting services; merge its inactive profile only after Deck stops."""
|
|
import hashlib,json,os,secrets,subprocess,sys,time,uuid
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parent.parent))
|
|
from catalog import Catalog
|
|
from seed_vc_runtime import SeedVCRuntime
|
|
|
|
def prepare(state,create_container=True):
|
|
state=Path(state).resolve();runtime=SeedVCRuntime(state/'seed_vc-runtime',None)
|
|
python,source=runtime.paths()
|
|
# The venv interpreter targets Deck's bundled Python, which lives inside its image.
|
|
if not (python.exists() or python.is_symlink()) or not (source/'app_svc.py').is_file():raise ValueError('Seed-VC-Laufzeit zuerst installieren.')
|
|
from seed_vc_runtime import ASSETS,REPO,MODEL_REVISION
|
|
ident=hashlib.sha256((REPO+MODEL_REVISION+ASSETS[0]['file']).encode()).hexdigest();pending=state/'seed_vc-profile-pending.json'
|
|
if pending.exists():
|
|
row=json.loads(pending.read_text())
|
|
if row.get('model_id')!=ident or row.get('api_id')!='seed-vc-singing':raise ValueError('Abweichendes vorbereitetes Seed-VC-Profil prüfen.')
|
|
else:
|
|
row=dict(id=uuid.uuid4().hex,revision=1,name='Seed-VC Gesang',api_id='seed-vc-singing',api_aliases=[],kind='voice',model_id=ident,parameters={},components={},presets=[],prompt_enhancer=None,updated_at=time.time())
|
|
pending.write_text(json.dumps(row,indent=2));os.chown(pending,65534,65534)
|
|
root=state/'seed_vc-data';root.mkdir(parents=True,exist_ok=True);os.chown(root,65534,65534)
|
|
settings=root/'settings.json'
|
|
if not settings.exists():settings.write_text(json.dumps({'device':'5080'}));os.chown(settings,65534,65534)
|
|
key=root/'bridge-key'
|
|
if not key.exists():key.write_text(secrets.token_urlsafe(48));key.chmod(0o600);os.chown(key,65534,65534)
|
|
if not create_container:
|
|
print('Seed-VC: inaktives Profil vorbereitet; kein Container gestartet oder registriert.');return
|
|
name='athena-seed-vc-web';found=subprocess.run(['docker','inspect',name],capture_output=True,text=True)
|
|
if found.returncode==0:
|
|
row=json.loads(found.stdout)[0];labels=row['Config'].get('Labels') or {}
|
|
if labels.get('io.athena-deck.managed')!='true' or labels.get('io.athena-deck.application')!='seed-vc-web':raise ValueError('Containername anderweitig belegt.')
|
|
if row['State']['Running']:raise ValueError('Vorhandene Seed-VC-UI läuft bereits; Vorbereitung verändert sie nicht.')
|
|
else:
|
|
subprocess.run(['docker','create','--name',name,'--network','host','--restart','unless-stopped','--label','io.athena-deck.managed=true','--label','io.athena-deck.role=application','--label','io.athena-deck.application=seed-vc-web','--read-only','--cap-drop','ALL','--security-opt','no-new-privileges:true','--pids-limit','128','--memory','512m','--cpus','1','--tmpfs','/tmp:rw,noexec,nosuid,size=128m,uid=65534,gid=65534','--mount','type=bind,src='+str(key)+',dst=/run/secrets/seed-vc-bridge,readonly','athena-seed-vc-web:0.1.0-deck2'],check=True,stdout=subprocess.DEVNULL)
|
|
print('Seed-VC: inaktives Profil vorbereitet, UI-Container gestoppt. Keine Endpunktfreigabe geändert.')
|
|
|
|
def apply_profile(state,deck='athena-deck-dev'):
|
|
from profiles import Profiles
|
|
result=subprocess.run(['docker','inspect',deck],capture_output=True,text=True,check=True)
|
|
if json.loads(result.stdout)[0]['State']['Running']:raise ValueError('Deck läuft: Profil erst im späteren Wartungsfenster übernehmen.')
|
|
state=Path(state);SeedVCRuntime(state/'seed_vc-runtime',None).ensure_library();row=json.loads((state/'seed_vc-profile-pending.json').read_text());profiles=Profiles(state/'profiles.json',Catalog(state/'models'))
|
|
existing=next((p for p in profiles.rows if p.get('api_id')==row['api_id']),None)
|
|
if existing:
|
|
if existing['model_id']!=row['model_id']:raise ValueError('Seed-VC API-ID bereits anders belegt.')
|
|
else:profiles.save(dict(id=None,revision=0,name=row['name'],api_id=row['api_id'],kind='voice',model_id=row['model_id'],parameters={}))
|
|
os.chown(state/'profiles.json',65534,65534)
|
|
print('Inaktives Seed-VC-Profil übernommen; Betriebsart und Freigaben unverändert.')
|
|
if __name__=='__main__':
|
|
if '--apply-profile' in sys.argv:apply_profile(sys.argv[1])
|
|
else:prepare(sys.argv[1],create_container='--no-container' not in sys.argv)
|