Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
|
@@ -20,13 +20,31 @@ app = FastAPI(
|
|
| 20 |
version="1.1.0",
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
@app.get("/health")
|
|
|
|
| 20 |
version="1.1.0",
|
| 21 |
)
|
| 22 |
|
| 23 |
+
tts: TTS | None = None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@app.on_event("startup")
|
| 27 |
+
async def load_model() -> None:
|
| 28 |
+
"""
|
| 29 |
+
Load the XTTSv2 + GPT model once when the application starts.
|
| 30 |
+
|
| 31 |
+
We create the model inside a worker thread so Auralis can freely
|
| 32 |
+
manage its own event loop without conflicting with FastAPI/uvicorn.
|
| 33 |
+
"""
|
| 34 |
+
global tts
|
| 35 |
+
|
| 36 |
+
if tts is not None:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
loop = asyncio.get_event_loop()
|
| 40 |
+
|
| 41 |
+
def _init_model() -> TTS:
|
| 42 |
+
return TTS().from_pretrained(
|
| 43 |
+
"AstraMindAI/xttsv2",
|
| 44 |
+
gpt_model="AstraMindAI/xtts2-gpt",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
tts = await loop.run_in_executor(None, _init_model)
|
| 48 |
|
| 49 |
|
| 50 |
@app.get("/health")
|