sachin sharma
fix for async methods as per PR
d481329
raw
history blame contribute delete
827 Bytes
"""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