Files
Athena-Deck/docs/maintenance/shared-qwen/accept_gui.py
T
Mikei386 c0bc5d3a1b Integrate Basalt telemetry and shared GPU speech runtimes
Publish the reviewed accumulated runtime, scheduler, profile, UI, native recipes and historical maintenance evidence. Includes Qwen GPU ASR correction and shared Anna/atelier ownership. Validated with 784 local tests, Python/JSON parsing and eight JavaScript syntax checks. Live GPU acceptance and full fresh-host restore limits remain documented.
2026-11-03 21:16:41 +01:00

32 lines
3.5 KiB
Python

"""Run ONLY inside browser_exec with an authenticated Deck browser session.
Uses normal same-origin atelier HTTP and a synthetic reference produced by
restore.py. Never extracts a cookie, reads a password, publishes a profile,
changes a mode or restarts/unloads a worker. No CLI execution environment.
"""
import base64,json,time
from pathlib import Path
OUT=Path('/opt/data/profiles/athena-deck/cache/scratch/shared-qwen-acceptance')
probe=js("(async()=>{const r=await fetch('/api/v1/voice');return {http:r.status,type:r.headers.get('content-type')};})()")
assert probe['http']==200 and 'application/json' in probe['type'],'Normal management login required; no test started'
goto_url('http://192.168.1.212:8108/stimmatelier/');wait_for_load()
selection=js("(async()=>{const r=await fetch('/api/v1/profiles');if(!r.ok)throw Error('Normal login required');const d=await r.json();const p=d.profiles.find(p=>p.kind==='voice'&&p.runnable&&p.model?.repo==='Qwen/Qwen3-TTS-12Hz-1.7B-Base');if(!p)throw Error('No runnable Qwen clone profile');const select=document.querySelector('#profile');select.value=p.id;select.dispatchEvent(new Event('change',{bubbles:true}));return {id:p.id,name:p.name};})()")
encoded=base64.b64encode((OUT/'reference.wav').read_bytes()).decode()
meta=json.loads((OUT/'restoration.json').read_text())
request=dict(profile_id=selection['id'],text='Die gemeinsame Stimme wird im Atelier getestet.',device='3060',language='German',reference_text=meta['reference_text'])
expression="(async()=>{const raw=atob("+json.dumps(encoded)+"),bytes=Uint8Array.from(raw,c=>c.charCodeAt(0));const data=new FormData();const fields="+json.dumps(request)+";for(const [k,v]of Object.entries(fields))data.set(k,v);data.set('file',new File([bytes],'synthetic-reference.wav',{type:'audio/wav'}));const r=await fetch('/api/v1/voice/start',{method:'POST',headers:{'X-Athena-Deck':'1'},body:data});const d=await r.json();if(!r.ok)throw Error(d.error||'Atelier request failed');return {id:d.id,state:d.state,profile_id:d.profile_id};})()"
job=js(expression);print('Actual authenticated shared-Qwen job started:',job)
deadline=time.monotonic()+180
while time.monotonic()<deadline:
state=js("(async()=>{const r=await fetch('/api/v1/voice');if(!r.ok)throw Error('Management session lost');const d=await r.json();return {job:d.job,shared:d.shared_tts,mode:d.mode};})()")
current=state['job'];assert current and current['id']==job['id'],'Another voice job replaced the result; stop instead of accepting it'
if current['state']!='running':break
time.sleep(.3)
else:raise RuntimeError('Bounded atelier check timed out; do not interrupt active work automatically')
assert current['state']=='complete',current
assert current.get('shared_tts') is True and state['shared']['loaded'] is True and state['mode']=='llm',state
playback=js("(async()=>{const r=await fetch('/api/v1/voice/audio?id="+job['id']+"');if(!r.ok)throw Error('Output not available');const b=new Uint8Array(await r.arrayBuffer());const signature=String.fromCharCode(...b.slice(0,4));if(signature!=='RIFF')throw Error('Not WAV');const j="+json.dumps(current)+";await showResult('voice',j,selected());return {wav:true,bytes:b.length,playerReady:!!document.querySelector('#output').src,downloadReady:!!document.querySelector('#download').href};})()")
result=dict(stage='actual shared atelier generation passed; final Anna/PID check pending',profile=selection,job=current,shared=state['shared'],mode=state['mode'],output=playback)
p=OUT/'atelier.json';p.write_text(json.dumps(result,indent=2));assert json.loads(p.read_text())==result
print(json.dumps(result))