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.
125 lines
3.7 KiB
Python
125 lines
3.7 KiB
Python
"""Mikes-Applio-UI – FastAPI application."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import logging
|
||
import os,secrets
|
||
from fastapi import Request
|
||
from fastapi.responses import JSONResponse
|
||
from contextlib import asynccontextmanager
|
||
from pathlib import Path
|
||
|
||
from fastapi import FastAPI
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
from fastapi.staticfiles import StaticFiles
|
||
|
||
from .api import (
|
||
diagnostics,
|
||
health,
|
||
jobs,
|
||
models,
|
||
presets,
|
||
realtime,
|
||
system,
|
||
uploads,
|
||
)
|
||
from .config import get_settings
|
||
from .jobs.queue import JobQueue
|
||
from .jobs.store import get_job_store
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
@asynccontextmanager
|
||
async def lifespan(app: FastAPI):
|
||
settings = get_settings()
|
||
logging.basicConfig(level=settings.log_level)
|
||
logger.info("Mikes-Applio-UI starting with real Applio runner")
|
||
|
||
store = get_job_store()
|
||
queue = JobQueue(store)
|
||
queue.start()
|
||
app.state.job_queue = queue
|
||
app.state.job_store = store
|
||
|
||
# Cleanup old jobs
|
||
cleaned = store.cleanup_old(settings.job_retention_days)
|
||
if cleaned:
|
||
logger.info("Cleaned up %d old jobs", cleaned)
|
||
|
||
yield
|
||
|
||
queue.stop()
|
||
from .adapters.runner import get_runner
|
||
runner = get_runner()
|
||
if hasattr(runner, 'unload'):
|
||
runner.unload()
|
||
logger.info("Mikes-Applio-UI stopped")
|
||
|
||
|
||
def create_app() -> FastAPI:
|
||
settings = get_settings()
|
||
|
||
app = FastAPI(
|
||
title="Mikes-Applio-UI",
|
||
description="Moderne Weboberfläche für Applio/RVC",
|
||
version="0.4.1",
|
||
lifespan=lifespan,
|
||
)
|
||
app.state.realtime_active = False
|
||
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=["*"],
|
||
allow_credentials=True,
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
|
||
@app.middleware("http")
|
||
async def disable_frontend_cache(request, call_next):
|
||
"""Prevent incompatible frontend modules from being mixed after deployments."""
|
||
response = await call_next(request)
|
||
path = request.url.path
|
||
if path == "/" or path.endswith((".html", ".js", ".css")):
|
||
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||
response.headers["Pragma"] = "no-cache"
|
||
response.headers["Expires"] = "0"
|
||
return response
|
||
|
||
@app.middleware("http")
|
||
async def bridge_auth(request, call_next):
|
||
key_file=os.environ.get('APPLIO_BRIDGE_KEY_FILE')
|
||
if key_file and not secrets.compare_digest(request.headers.get('X-Applio-Bridge',''),Path(key_file).read_text().strip()):
|
||
return JSONResponse({'detail':'Deck-Brücke erforderlich.'},status_code=403)
|
||
return await call_next(request)
|
||
|
||
@app.post('/api/deck/unload')
|
||
def unload():
|
||
from .adapters.runner import get_runner
|
||
runner=get_runner()
|
||
if hasattr(runner,'unload'):runner.unload()
|
||
return {'ok':True}
|
||
|
||
# API routes
|
||
app.include_router(health.router, prefix="/api")
|
||
app.include_router(system.router, prefix="/api")
|
||
app.include_router(models.router, prefix="/api")
|
||
app.include_router(presets.router, prefix="/api")
|
||
app.include_router(uploads.router, prefix="/api")
|
||
app.include_router(jobs.router, prefix="/api")
|
||
app.include_router(realtime.router, prefix="/api")
|
||
app.include_router(diagnostics.router, prefix="/api")
|
||
|
||
# Serve frontend static files (no build step – plain static site)
|
||
frontend_dir = settings.frontend_dir
|
||
if not frontend_dir.is_absolute():
|
||
frontend_dir = Path(__file__).parent.parent.parent / frontend_dir
|
||
if frontend_dir.exists():
|
||
app.mount("/", StaticFiles(directory=str(frontend_dir), html=True), name="frontend")
|
||
|
||
return app
|
||
|
||
|
||
app = create_app()
|