added support for additional more user-friendly interfaces, improved some part of the application loading process to make it a bit simpler
This commit is contained in:
parent
1a49aa3779
commit
f647c960dd
20 changed files with 353 additions and 107 deletions
40
source/api/interface/base/BaseInterface.py
Normal file
40
source/api/interface/base/BaseInterface.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
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_gradio_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_gradio_application(),
|
||||
self.route
|
||||
)
|
1
source/api/interface/base/__init__.py
Normal file
1
source/api/interface/base/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .BaseInterface import BaseInterface
|
Loading…
Add table
Add a link
Reference in a new issue