File size: 827 Bytes
da2b98d 5ddae77 da2b98d 5ddae77 d481329 da2b98d 5ddae77 d481329 da2b98d 5ddae77 da2b98d 5ddae77 |
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 |
"""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.
"""
@abstractmethod
def load_model(self) -> None:
"""Load model weights and processors. Called once at startup."""
pass
@abstractmethod
def predict(self, request: TRequest) -> TResponse:
"""Run inference and return typed response."""
pass
@property
@abstractmethod
def is_loaded(self) -> bool:
"""Check if model is loaded and ready."""
pass
|