| """Abstract base class for ML inference services.""" | |
| from abc import ABC, abstractmethod | |
| from typing import Generic, TypeVar | |
| from pydantic import BaseModel | |
| TRequest = TypeVar('TRequest', bound=BaseModel) | |
| TResponse = TypeVar('TResponse', bound=BaseModel) | |
| class InferenceService(ABC, Generic[TRequest, TResponse]): | |
| """ | |
| Base class for inference services. Subclass this to integrate your model. | |
| """ | |
| def load_model(self) -> None: | |
| """Load model weights and processors. Called once at startup.""" | |
| pass | |
| def predict(self, request: TRequest) -> TResponse: | |
| """Run inference and return typed response.""" | |
| pass | |
| def is_loaded(self) -> bool: | |
| """Check if model is loaded and ready.""" | |
| pass | |