File size: 810 Bytes
bf6e45c
 
 
 
958fece
bf6e45c
 
 
 
 
 
 
 
 
 
 
 
 
958fece
bf6e45c
958fece
 
bf6e45c
958fece
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import threading
from contextlib import asynccontextmanager

from fastapi import FastAPI
from routers import extraction, tts
from services import tts_service


@asynccontextmanager
async def lifespan(app: FastAPI):
    # Warm the TTS model off the request path so the first /tts call doesn't
    # pay model-load cost. Runs in a daemon thread; if TTS deps are missing it
    # quietly no-ops and /tts keeps degrading to 503. Disable with TTS_WARMUP=0.
    if os.getenv("TTS_WARMUP", "1") != "0":
        threading.Thread(target=tts_service.warmup, daemon=True).start()
    yield


app = FastAPI(title="Smartfolio Python Service", version="1.0.0", lifespan=lifespan)

app.include_router(extraction.router)
app.include_router(tts.router)


@app.get("/health")
def health():
    return {"status": "ok"}