File size: 841 Bytes
c3717d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9451378
c3717d3
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Dependency injection for FastAPI
"""
from typing import Optional
from fastapi import HTTPException
from api.services.model_service import ModelService

# Global model service instance
model_service: Optional[ModelService] = None


def get_model_service() -> ModelService:
    """Dependency injection for model service"""
    if model_service is None:
        raise HTTPException(status_code=503, detail="Models not loaded")
    return model_service


async def initialize_models():
    """Initialize models on startup"""
    global model_service
    print("πŸš€ Loading CodeBERT models...")
    model_service = ModelService()  # Models load in __init__
    print("βœ… Models loaded successfully!")


def cleanup_models():
    """Cleanup on shutdown"""
    global model_service
    print("πŸ‘‹ Shutting down...")
    model_service = None