40 lines
932 B
Python
40 lines
932 B
Python
import abc
|
|
|
|
import fastapi
|
|
import gradio
|
|
|
|
import source
|
|
|
|
|
|
class BaseInterface(abc.ABC):
|
|
def __init__(self, model: "source._model.base.BaseModel"):
|
|
self.model = model
|
|
|
|
@property
|
|
def route(self) -> str:
|
|
"""
|
|
The route to the interface
|
|
:return: the route to the interface
|
|
"""
|
|
|
|
return f"{self.model.api_base}/interface"
|
|
|
|
@abc.abstractmethod
|
|
def get_application(self) -> gradio.Blocks:
|
|
"""
|
|
Get a gradio application
|
|
:return: a gradio application
|
|
"""
|
|
|
|
def mount(self, application: fastapi.FastAPI) -> None:
|
|
"""
|
|
Mount the interface on an application
|
|
:param application: the application to mount the interface on
|
|
:param path: the path where to mount the application
|
|
"""
|
|
|
|
gradio.mount_gradio_app(
|
|
application,
|
|
self.get_application(),
|
|
self.route
|
|
)
|