Added an on startup section for fastapi
Browse files- app/main.py +11 -11
app/main.py
CHANGED
|
@@ -10,17 +10,6 @@ from app.services.ocr_service import OCRService
|
|
| 10 |
from app.schemas import CardResponse
|
| 11 |
from app.config import settings
|
| 12 |
|
| 13 |
-
# --------------------
|
| 14 |
-
# ----- LIFESPAN -----
|
| 15 |
-
# --------------------
|
| 16 |
-
|
| 17 |
-
@app.on_event("startup")
|
| 18 |
-
async def startup_event():
|
| 19 |
-
"""Load models and indexes at startup."""
|
| 20 |
-
app.state.embedding_service = EmbeddingService()
|
| 21 |
-
app.state.similarity_service = SimilarityService()
|
| 22 |
-
app.state.ocr_service = OCRService()
|
| 23 |
-
print("Models and indexes loaded successfully.")
|
| 24 |
|
| 25 |
|
| 26 |
|
|
@@ -44,6 +33,17 @@ app.add_middleware(
|
|
| 44 |
# --------------------
|
| 45 |
# ----- ROUTES -------
|
| 46 |
# --------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
@app.get("/")
|
| 48 |
def root():
|
| 49 |
return {"message": "Pokemon Card API running"}
|
|
|
|
| 10 |
from app.schemas import CardResponse
|
| 11 |
from app.config import settings
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
|
|
|
|
| 33 |
# --------------------
|
| 34 |
# ----- ROUTES -------
|
| 35 |
# --------------------
|
| 36 |
+
|
| 37 |
+
@app.on_event("startup")
|
| 38 |
+
async def startup_event():
|
| 39 |
+
"""Load models and indexes at startup."""
|
| 40 |
+
app.state.embedding_service = EmbeddingService()
|
| 41 |
+
app.state.similarity_service = SimilarityService()
|
| 42 |
+
app.state.ocr_service = OCRService()
|
| 43 |
+
print("Models and indexes loaded successfully.")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
@app.get("/")
|
| 48 |
def root():
|
| 49 |
return {"message": "Pokemon Card API running"}
|