Added an on startup section for fastapi
Browse files- app/__pycache__/main.cpython-311.pyc +0 -0
- app/main.py +8 -8
app/__pycache__/main.cpython-311.pyc
CHANGED
|
Binary files a/app/__pycache__/main.cpython-311.pyc and b/app/__pycache__/main.cpython-311.pyc differ
|
|
|
app/main.py
CHANGED
|
@@ -14,15 +14,13 @@ from app.config import settings
|
|
| 14 |
# ----- LIFESPAN -----
|
| 15 |
# --------------------
|
| 16 |
|
| 17 |
-
@
|
| 18 |
-
async def
|
| 19 |
-
|
| 20 |
app.state.embedding_service = EmbeddingService()
|
| 21 |
app.state.similarity_service = SimilarityService()
|
| 22 |
app.state.ocr_service = OCRService()
|
| 23 |
-
print("Models and
|
| 24 |
-
yield
|
| 25 |
-
print("Shutting down.")
|
| 26 |
|
| 27 |
|
| 28 |
|
|
@@ -32,8 +30,6 @@ async def lifespan(app: FastAPI):
|
|
| 32 |
|
| 33 |
app = FastAPI(
|
| 34 |
title="Pokemon Card Image Processor",
|
| 35 |
-
version="1.0.0",
|
| 36 |
-
lifespan=lifespan
|
| 37 |
)
|
| 38 |
|
| 39 |
app.add_middleware(
|
|
@@ -48,6 +44,10 @@ app.add_middleware(
|
|
| 48 |
# --------------------
|
| 49 |
# ----- ROUTES -------
|
| 50 |
# --------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
@app.get("/health")
|
| 53 |
def health():
|
|
|
|
| 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 |
|
|
|
|
| 30 |
|
| 31 |
app = FastAPI(
|
| 32 |
title="Pokemon Card Image Processor",
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
app.add_middleware(
|
|
|
|
| 44 |
# --------------------
|
| 45 |
# ----- ROUTES -------
|
| 46 |
# --------------------
|
| 47 |
+
@app.get("/")
|
| 48 |
+
def root():
|
| 49 |
+
return {"message": "Pokemon Card API running"}
|
| 50 |
+
|
| 51 |
|
| 52 |
@app.get("/health")
|
| 53 |
def health():
|