Spaces:
Build error
Build error
feat: backend entrypoint ve core analysis routes eklendi
Browse files- app/main.py +16 -1
app/main.py
CHANGED
|
@@ -4,7 +4,9 @@ CrownCode backend entrypoint with enhanced error handling.
|
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
|
|
|
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
|
@@ -42,7 +44,20 @@ def _load_origins() -> list[str]:
|
|
| 42 |
return origins
|
| 43 |
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
@app.get("/")
|
|
|
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
|
| 7 |
+
import asyncio
|
| 8 |
import os
|
| 9 |
+
from contextlib import asynccontextmanager
|
| 10 |
|
| 11 |
from fastapi import FastAPI, Request
|
| 12 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 44 |
return origins
|
| 45 |
|
| 46 |
|
| 47 |
+
@asynccontextmanager
|
| 48 |
+
async def lifespan(_app: FastAPI):
|
| 49 |
+
# On the Space (AURIS_WARMUP=1 in the Dockerfile) load the models and
|
| 50 |
+
# compile librosa's numba code before the first visitor; off in tests.
|
| 51 |
+
warm_task = None
|
| 52 |
+
if os.getenv("AURIS_WARMUP") == "1":
|
| 53 |
+
from .routes.analyze import warm_up
|
| 54 |
+
warm_task = asyncio.create_task(warm_up())
|
| 55 |
+
yield
|
| 56 |
+
if warm_task is not None and not warm_task.done():
|
| 57 |
+
warm_task.cancel()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
app = FastAPI(title="CrownCode Backend API", version="0.1.0", lifespan=lifespan)
|
| 61 |
|
| 62 |
|
| 63 |
@app.get("/")
|