21 lines
488 B
Python
21 lines
488 B
Python
import os
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from app.config.logging import logger
|
|
from app.config.settings import settings
|
|
from app.ml.model_manager import model_manager
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
if settings.HF_TOKEN:
|
|
os.environ["HF_TOKEN"] = settings.HF_TOKEN
|
|
|
|
logger.info("Loading AI models...")
|
|
model_manager.initialize()
|
|
logger.info("AI models loaded.")
|
|
yield
|
|
logger.info("Stopping AI Service...")
|