Spaces:
Sleeping
Sleeping
| """FastAPI dependency injection: DB sessions and model loading.""" | |
| from functools import lru_cache | |
| from typing import Generator | |
| import joblib | |
| from sqlalchemy.orm import Session | |
| from customer_intelligence.config import settings | |
| from customer_intelligence.db import SessionLocal | |
| def get_db() -> Generator[Session, None, None]: | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def _load_churn_model(): | |
| return joblib.load(settings.churn_model_path) | |
| def _load_segmentation_model(): | |
| return joblib.load(settings.segmentation_model_path) | |
| def get_churn_model(): | |
| return _load_churn_model() | |
| def get_segmentation_model(): | |
| return _load_segmentation_model() | |