Spaces:
Running
Running
File size: 1,268 Bytes
18869bb |
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 33 34 35 36 37 38 39 40 41 42 |
from abc import ABC, abstractmethod
from typing import Any, Dict, Optional
import gradio as gr
class BaseModel(ABC):
"""Base class for all ML/AI models."""
def __init__(self, name: str, description: str):
self.name = name
self.description = description
self._model: Optional[Any] = None
self._interface: Optional[gr.Interface] = None
@abstractmethod
def load_model(self) -> None:
"""Load the model into memory."""
pass
@abstractmethod
def create_interface(self) -> gr.Interface:
"""Create and return a Gradio interface for the model."""
pass
@abstractmethod
async def predict(self, *args, **kwargs) -> Any:
"""Make predictions using the model."""
pass
def get_interface(self) -> gr.Interface:
"""Get or create the Gradio interface."""
if self._interface is None:
self._interface = self.create_interface()
return self._interface
def get_info(self) -> Dict[str, str]:
"""Get model information."""
return {
"name": self.name,
"description": self.description,
"status": "loaded" if self._model is not None else "unloaded"
} |