Replace Deck video generation with selected external service lifecycle

This commit is contained in:
Mikei386
2026-09-29 14:24:52 +02:00
parent 71e8345606
commit badc7701fa
23 changed files with 219 additions and 636 deletions
+12 -30
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""Athena Deck prototype: loopback API, owned model processes, read-only telemetry."""
from video_runtime import VideoRuntime
from video import Video
from execution_setup import assess as execution_assess
import argparse
@@ -101,18 +100,15 @@ class Server(ThreadingHTTPServer):
self.endpoint=Endpoint(self.catalog.root.parent,self.profiles,self.worker,self.scheduler,self.image_tests,self.credentials,self.server_port)
self.endpoint.tts=self.tts_tests
self.endpoint.stt=self.stt
self.chat_tests=ChatTests(self.profiles,self.worker,self.scheduler)
self.auto_tests=AutoTests(self.catalog.root.parent/'auto-tests.json',self.profiles,self.worker,self.scheduler)
def stop_gpu_work():
self.auto_tests.stop();self.chat_tests.stop();self.image_tests.stop();self.tts_tests.stop();self.worker.stop()
self.video=Video(self.scheduler,stop_gpu_work,self.docker,self.catalog.root.parent/'video')
self.endpoint.video=self.video
if self.endpoint.config['autostart']:
try:self.endpoint.start()
except ValueError as exc:self.endpoint.error=str(exc)
self.chat_tests=ChatTests(self.profiles,self.worker,self.scheduler)
self.auto_tests=AutoTests(self.catalog.root.parent/'auto-tests.json',self.profiles,self.worker,self.scheduler)
self.video_runtime=VideoRuntime(self.catalog.root.parent/'video-runtime')
def stop_gpu_work():
self.auto_tests.stop();self.chat_tests.stop();self.image_tests.stop();self.tts_tests.stop();self.worker.stop()
self.video=Video(self.catalog.root.parent/'video',self.profiles,self.video_runtime,self.scheduler,stop_gpu_work)
self.profiles.video_blockers=self.video.blockers
self.profiles.video_runtime_ready=lambda:self.video_runtime.status()["installed"]
self.endpoint.video=self.video
self.sessions = {}
self.login_attempts = []
self.auth_lock = threading.Lock()
@@ -254,7 +250,7 @@ class Handler(BaseHTTPRequestHandler):
return self.headers.get('Host') in allowed
def execution_setup(self, model, profile=None):
installed={'stt':bool(self.server.runtime.status().get('active')),'chat':bool(self.server.runtime.status().get('active')),'image':self.server.image_runtime.status().get('installed',False),'audio':self.server.tts_runtime.status().get('installed',False),'video':self.server.video_runtime.status().get('installed',False)}
installed={'stt':bool(self.server.runtime.status().get('active')),'chat':bool(self.server.runtime.status().get('active')),'image':self.server.image_runtime.status().get('installed',False),'audio':self.server.tts_runtime.status().get('installed',False),'video':False}
return execution_assess(model,installed,profile)
def do_GET(self):
@@ -285,16 +281,7 @@ class Handler(BaseHTTPRequestHandler):
if urlsplit(self.path).path == '/api/v1/tts/audio':
try:return self.respond(self.server.tts_tests.audio(parse_qs(urlsplit(self.path).query).get('id',[''])[0]),mime='audio/wav')
except (OSError,ValueError):return self.respond({'error':'Audio nicht verfügbar.'},404)
if urlsplit(self.path).path == '/api/v1/video/content':
try:
path=self.server.video.result(parse_qs(urlsplit(self.path).query).get('id',[''])[0])
self.send_response(200);self.send_header('Content-Type','video/mp4');self.send_header('Content-Length',str(path.stat().st_size));self.send_header('Cache-Control','no-store');self.end_headers()
with path.open('rb') as source:
while chunk:=source.read(1024*1024):self.wfile.write(chunk)
return
except ValueError as exc:return self.respond({'error':str(exc)},404)
if self.path == '/api/v1/video':return self.respond(self.server.video.status())
if self.path == '/api/v1/video-runtime':return self.respond(self.server.video_runtime.status())
if self.path == '/api/v1/image-runtime':return self.respond(self.server.image_runtime.status())
if self.path == '/api/v1/image-tests':return self.respond(self.server.image_tests.status())
if urlsplit(self.path).path == '/api/v1/image-tests/image':
@@ -408,16 +395,13 @@ class Handler(BaseHTTPRequestHandler):
if data:raise ValueError('Keine Parameter erwartet.')
return self.respond(self.server.chat_tests.stop() if self.path.endswith('/cancel') else self.server.chat_tests.unload())
except ValueError as exc:return self.respond({'error':str(exc)},400)
if self.path in ('/api/v1/video/mode','/api/v1/video/profile','/api/v1/video/generate','/api/v1/video-runtime/install','/api/v1/video-runtime/cancel'):
if self.path in ('/api/v1/video/mode','/api/v1/video/service'):
try:
data=self.read_json()
if self.path.endswith('/mode') and set(data)=={'mode'}:return self.respond(self.server.video.switch(data['mode']))
if self.path.endswith('/profile') and set(data)=={'id'}:return self.respond(self.server.video.select(data['id']))
if self.path.endswith('/generate'):return self.respond(self.server.video.generate(data),202)
if data:raise ValueError('Ungültige Video-Parameter.')
return self.respond(self.server.video_runtime.start() if self.path.endswith('/install') else self.server.video_runtime.stop())
except ValueError as exc:return self.respond({'error':str(exc)},400)
except Exception:return self.respond({'error':'Video-Aktion fehlgeschlagen.'},503)
if self.path.endswith('/service') and set(data)=={'id'}:return self.respond(self.server.video.select(data['id']))
if set(data)!={'mode'}:raise ValueError('Nur Modus llm oder video erwartet.')
return self.respond(self.server.video.switch(data['mode']))
except (OSError,ValueError) as exc:return self.respond({'error':str(exc)},400)
if self.path in ('/api/v1/endpoint/start','/api/v1/endpoint/stop','/api/v1/endpoint/config','/api/v1/endpoint/profile'):
try:
data=self.read_json();ep=self.server.endpoint
@@ -475,7 +459,6 @@ class Handler(BaseHTTPRequestHandler):
if self.path == '/api/v1/profiles/delete':
try:
data=self.read_json()
if self.server.video.selected==data.get('id') and self.server.video.status()['state'] in ('ready','switching'):raise ValueError('Aktives Videoprofil zuerst durch Wechsel auf LLM entladen.')
with self.server.image_tests.lock, self.server.tts_tests.lock, self.server.stt.lock:
stt_job=self.server.stt.job
if stt_job and stt_job.get("state")=="running" and stt_job.get("profile_id")==data.get("id"):raise ValueError("Dieses STT-Profil wird gerade ausgeführt. Zuerst den Auftrag beenden.")
@@ -538,7 +521,6 @@ def main():
server.auto_tests.stop()
server.chat_tests.stop()
server.video.close()
server.video_runtime.stop()
server.endpoint.close()
server.stt.stop()
server.tts_tests.stop()