Files
Athena-Deck/deploy/activate_acestep.py
T

20 lines
1.6 KiB
Python

"""Run only after stopping Deck; creates the prepared profile without changing mode."""
import json,os,sys
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parent.parent))
from catalog import Catalog
from profiles import Profiles
from acestep_models import ACE_REPO,ACE_COMPONENTS
def activate(state):
state=Path(state);plan=json.loads((state/'acestep-import-plan.json').read_text());catalog=Catalog(state/'models');profiles=Profiles(state/'profiles.json',catalog)
main=plan[ACE_REPO+'/model-00001-of-00004.safetensors'];existing=next((p for p in profiles.rows if p.get('api_id')=='ace-step-xl-sft'),None)
if existing and existing['model_id']!=main:raise ValueError('ACE-Step API-ID bereits anders verwendet.')
row=existing or profiles.save(dict(id=None,revision=0,name='ACE-Step 1.5 XL-SFT',api_id='ace-step-xl-sft',kind='music',model_id=main,parameters={}))
components={role:plan[info.get('repo',ACE_REPO)+'/'+info['files'][0]] for role,info in ACE_COMPONENTS.items()}
if row.get('components')!=components:row=profiles.assign(dict(id=row['id'],revision=row['revision'],components=components))
endpoint=state/'endpoint.json';config=json.loads(endpoint.read_text());config['enabled_profiles']=sorted(set(config['enabled_profiles'])|{row['id']});temp=endpoint.with_suffix('.tmp');temp.write_text(json.dumps(config));temp.replace(endpoint)
for p in (state/'profiles.json',endpoint):os.chown(p,65534,65534)
print(json.dumps(dict(profile=row['name'],api_id=row['api_id'],components=len(components),mode_unchanged=True)))
if __name__=='__main__':activate(sys.argv[1])