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.
150 lines
4.9 KiB
Python
150 lines
4.9 KiB
Python
"""Diagnostics endpoint – safe, no secrets."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import platform
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
from fastapi import APIRouter, Request
|
||
|
||
from .. import __version__
|
||
from ..adapters.runner import get_runner
|
||
from ..config import get_settings
|
||
from ..jobs.enums import JobStatus
|
||
from ..services.models import discover_models, models_without_index
|
||
|
||
router = APIRouter(tags=["diagnostics"])
|
||
|
||
|
||
@router.get("/diagnostics")
|
||
def diagnostics(request: Request):
|
||
settings = get_settings()
|
||
runner = get_runner()
|
||
store = _get_store(request)
|
||
|
||
models = discover_models()
|
||
models_no_index = models_without_index()
|
||
|
||
# Disk usage
|
||
disk_info = _get_disk_info(settings.results_dir)
|
||
|
||
# Running jobs
|
||
queue = request.app.state.job_queue
|
||
running = queue.get_running()
|
||
|
||
# Last error / last success
|
||
recent = store.list(limit=20)
|
||
last_error = next((j for j in recent if j.status == JobStatus.FAILED), None)
|
||
last_success = next((j for j in recent if j.status == JobStatus.SUCCESS), None)
|
||
|
||
report = {
|
||
"version": __version__,
|
||
"runner": runner.name(),
|
||
"runner_available": runner.is_available(),
|
||
"applio_commit": _get_applio_commit(settings.applio_container, settings.applio_workdir),
|
||
"python_version": sys.version,
|
||
"platform": platform.platform(),
|
||
"ffmpeg_available": shutil.which("ffmpeg") is not None,
|
||
"models_found": len(models),
|
||
"models_without_index": len(models_no_index),
|
||
"models_without_index_names": [m.name for m in models_no_index],
|
||
"disk": disk_info,
|
||
"running_jobs": len(running),
|
||
"last_error": {
|
||
"id": last_error.id,
|
||
"type": last_error.type.value,
|
||
"error": last_error.error,
|
||
"finished_at": last_error.finished_at.isoformat() if last_error and last_error.finished_at else None,
|
||
} if last_error else None,
|
||
"last_success": {
|
||
"id": last_success.id,
|
||
"type": last_success.type.value,
|
||
"finished_at": last_success.finished_at.isoformat() if last_success and last_success.finished_at else None,
|
||
} if last_success else None,
|
||
"configured_dirs": {
|
||
"models": str(settings.models_dir),
|
||
"datasets": str(settings.datasets_dir),
|
||
"jobs": str(settings.jobs_dir),
|
||
"results": str(settings.results_dir),
|
||
"uploads": str(settings.uploads_dir),
|
||
},
|
||
}
|
||
return report
|
||
|
||
|
||
@router.get("/diagnostics/report")
|
||
def diagnostics_report(request: Request):
|
||
"""Return a copyable plain-text diagnostic report (no secrets)."""
|
||
d = diagnostics(request)
|
||
lines = [
|
||
"Mikes-Applio-UI Diagnosebericht",
|
||
"=" * 40,
|
||
f"Version: {d['version']}",
|
||
f"Runner: {d['runner']} (verfügbar: {d['runner_available']})",
|
||
f"Applio-Commit: {d['applio_commit']}",
|
||
f"Python: {d['python_version']}",
|
||
f"Plattform: {d['platform']}",
|
||
f"FFmpeg: {'verfügbar' if d['ffmpeg_available'] else 'NICHT verfügbar'}",
|
||
"",
|
||
"Modelle:",
|
||
f" Gefunden: {d['models_found']}",
|
||
f" Ohne Index: {d['models_without_index']}",
|
||
]
|
||
for name in d["models_without_index_names"]:
|
||
lines.append(f" - {name}")
|
||
lines.extend([
|
||
"",
|
||
"Speicher:",
|
||
f" Freier Platz: {d['disk']['free_gb']:.1f} GB",
|
||
f" Belegt: {d['disk']['used_gb']:.1f} GB",
|
||
"",
|
||
"Aufträge:",
|
||
f" Laufend: {d['running_jobs']}",
|
||
])
|
||
if d["last_error"]:
|
||
lines.append(f" Letzter Fehler: {d['last_error']['error']}")
|
||
if d["last_success"]:
|
||
lines.append(f" Letzter Erfolg: {d['last_success']['type']}")
|
||
lines.extend([
|
||
"",
|
||
"Konfigurierte Verzeichnisse:",
|
||
])
|
||
for k, v in d["configured_dirs"].items():
|
||
lines.append(f" {k}: {v}")
|
||
return {"report": "\n".join(lines)}
|
||
|
||
|
||
def _get_store(request: Request):
|
||
return request.app.state.job_store
|
||
|
||
|
||
def _get_disk_info(path: Path) -> dict:
|
||
try:
|
||
usage = shutil.disk_usage(str(path))
|
||
return {
|
||
"free_gb": usage.free / (1024**3),
|
||
"used_gb": usage.used / (1024**3),
|
||
"total_gb": usage.total / (1024**3),
|
||
}
|
||
except OSError:
|
||
return {"free_gb": 0, "used_gb": 0, "total_gb": 0}
|
||
|
||
|
||
def _get_applio_commit(container: str, workdir: str) -> str:
|
||
"""Read the running Applio revision instead of reporting a stale constant."""
|
||
try:
|
||
result = subprocess.run(
|
||
["docker", "exec", "-w", workdir, container, "git", "rev-parse", "HEAD"],
|
||
capture_output=True,
|
||
text=True,
|
||
timeout=5,
|
||
check=False,
|
||
)
|
||
revision = result.stdout.strip()
|
||
return revision if result.returncode == 0 and revision else "nicht ermittelbar"
|
||
except (subprocess.TimeoutExpired, FileNotFoundError):
|
||
return "nicht ermittelbar"
|