Restructure into asr/tts packages and add TTS tab skeleton
Split the single ASR gateway into app/main.py (entrypoint) + app/core (shared env helpers) + app/asr (all existing ASR logic, unchanged behavior) + app/tts (placeholder router/config, no engine yet), so a real TTS backend can be dropped in later without reshuffling ASR code. API moved under /asr/* and /tts/* prefixes; UI gained a top-level ASR/TTS tab switcher built on a reusable nested .tab-group mechanism, with JS split into common.js/asr.js/tts.js. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
48
app/main.py
Normal file
48
app/main.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from asr.config import ensure_runtime_dirs
|
||||
from asr.router import router as asr_router
|
||||
from tts.router import router as tts_router
|
||||
|
||||
app = FastAPI(title="ASR/TTS Gateway", docs_url="/docs", redoc_url="/redoc")
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
UI_DIR = Path("/app/ui")
|
||||
|
||||
app.include_router(asr_router, prefix="/asr", tags=["asr"])
|
||||
app.include_router(tts_router, prefix="/tts", tags=["tts"])
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup() -> None:
|
||||
ensure_runtime_dirs()
|
||||
if UI_DIR.exists():
|
||||
app.mount("/ui", StaticFiles(directory=str(UI_DIR), html=True), name="ui")
|
||||
app.mount("/assets", StaticFiles(directory=str(UI_DIR / "assets")), name="assets")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health() -> Dict[str, Any]:
|
||||
return {"status": "ok", "ui_installed": UI_DIR.exists(), "api": "/docs"}
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def root() -> Any:
|
||||
index = UI_DIR / "index.html"
|
||||
if index.exists():
|
||||
return FileResponse(index)
|
||||
return JSONResponse({"status": "ok", "message": "UI not installed", "api": "/docs"})
|
||||
Reference in New Issue
Block a user