mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
feat: models lazy loader
This commit is contained in:
@ -1,57 +1,112 @@
|
|||||||
from .emotion import Emotion
|
|
||||||
from .chat import Chat
|
|
||||||
from .audio_chat import AudioChat
|
|
||||||
from .sentiment import Sentiment
|
|
||||||
from .tts import TTS
|
|
||||||
from .asr import ASR
|
|
||||||
from .audio_to_text import AudioToText
|
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
from .fastchat import Fastchat
|
from injector import inject, singleton, Injector
|
||||||
from .g2e import G2E
|
from ..configuration import BlackboxConf
|
||||||
from .text_and_image import TextAndImage
|
|
||||||
from .melotts import MeloTTS
|
blackboxConf = Injector().get(BlackboxConf)
|
||||||
from .vlms import VLMS
|
|
||||||
from .chroma_query import ChromaQuery
|
def model_loader(lazy=blackboxConf.lazyloading):
|
||||||
from .chroma_upsert import ChromaUpsert
|
def load(init_fun):
|
||||||
from .chroma_chat import ChromaChat
|
model = None
|
||||||
from injector import inject, singleton
|
if not lazy:
|
||||||
|
model = init_fun()
|
||||||
|
def inner():
|
||||||
|
nonlocal model
|
||||||
|
if model is None:
|
||||||
|
model = init_fun()
|
||||||
|
return model
|
||||||
|
return inner
|
||||||
|
return load
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def text_and_image_loader():
|
||||||
|
from .text_and_image import TextAndImage
|
||||||
|
return Injector().get(TextAndImage)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def audio_chat_loader():
|
||||||
|
from .audio_chat import AudioChat
|
||||||
|
return Injector().get(AudioChat)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def sentiment_loader():
|
||||||
|
from .sentiment import Sentiment
|
||||||
|
return Injector().get(Sentiment)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def g2e_loader():
|
||||||
|
from .g2e import G2E
|
||||||
|
return Injector().get(G2E)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def asr_loader():
|
||||||
|
from .asr import ASR
|
||||||
|
return Injector().get(ASR)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def vlms_loader():
|
||||||
|
from .vlms import VLMS
|
||||||
|
return Injector().get(VLMS)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def melotts_loader():
|
||||||
|
from .melotts import MeloTTS
|
||||||
|
return Injector().get(MeloTTS)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def tts_loader():
|
||||||
|
from .tts import TTS
|
||||||
|
return Injector().get(TTS)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def emotion_loader():
|
||||||
|
from .emotion import Emotion
|
||||||
|
return Injector().get(Emotion)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def fastchat_loader():
|
||||||
|
from .fastchat import Fastchat
|
||||||
|
return Injector().get(Fastchat)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def chat_loader():
|
||||||
|
from .chat import Chat
|
||||||
|
return Injector().get(Chat)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def chroma_query_loader():
|
||||||
|
from .chroma_query import ChromaQuery
|
||||||
|
return Injector().get(ChromaQuery)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def chroma_upsert_loader():
|
||||||
|
from .chroma_upsert import ChromaUpsert
|
||||||
|
return Injector().get(ChromaUpsert)
|
||||||
|
|
||||||
|
@model_loader(lazy=blackboxConf.lazyloading)
|
||||||
|
def chroma_chat_load():
|
||||||
|
from .chroma_chat import ChromaChat
|
||||||
|
return Injector().get(ChromaChat)
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class BlackboxFactory:
|
class BlackboxFactory:
|
||||||
models = {}
|
models = {}
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
def __init__(self,
|
def __init__(self,) -> None:
|
||||||
audio_to_text: AudioToText,
|
self.models["asr"] = asr_loader
|
||||||
asr: ASR,
|
self.models["tts"] = tts_loader
|
||||||
tts: TTS,
|
self.models["sentiment_engine"] = sentiment_loader
|
||||||
sentiment_engine: Sentiment,
|
self.models["emotion"] = emotion_loader
|
||||||
emotion: Emotion,
|
self.models["fastchat"] = fastchat_loader
|
||||||
fastchat: Fastchat,
|
self.models["audio_chat"] = audio_chat_loader
|
||||||
audio_chat: AudioChat,
|
self.models["g2e"] = g2e_loader
|
||||||
g2e: G2E,
|
self.models["text_and_image"] = text_and_image_loader
|
||||||
text_and_image: TextAndImage,
|
self.models["chroma_query"] = chroma_query_loader
|
||||||
melotts: MeloTTS,
|
self.models["chroma_upsert"] = chroma_upsert_loader
|
||||||
vlms: VLMS,
|
self.models["chroma_chat"] = chroma_chat_load
|
||||||
chroma_query: ChromaQuery,
|
self.models["melotts"] = melotts_loader
|
||||||
chroma_upsert: ChromaUpsert,
|
self.models["vlms"] = vlms_loader
|
||||||
chroma_chat: ChromaChat,
|
self.models["chat"] = chat_loader
|
||||||
chat: Chat) -> None:
|
|
||||||
self.models["audio_to_text"] = audio_to_text
|
|
||||||
self.models["asr"] = asr
|
|
||||||
self.models["tts"] = tts
|
|
||||||
self.models["sentiment_engine"] = sentiment_engine
|
|
||||||
self.models["emotion"] = emotion
|
|
||||||
self.models["fastchat"] = fastchat
|
|
||||||
self.models["audio_chat"] = audio_chat
|
|
||||||
self.models["g2e"] = g2e
|
|
||||||
self.models["text_and_image"] = text_and_image
|
|
||||||
self.models["chroma_query"] = chroma_query
|
|
||||||
self.models["chroma_upsert"] = chroma_upsert
|
|
||||||
self.models["chroma_chat"] = chroma_chat
|
|
||||||
self.models["melotts"] = melotts
|
|
||||||
self.models["vlms"] = vlms
|
|
||||||
self.models["chat"] = chat
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.processing(*args, **kwargs)
|
return self.processing(*args, **kwargs)
|
||||||
@ -60,4 +115,4 @@ class BlackboxFactory:
|
|||||||
model = self.models.get(blackbox_name)
|
model = self.models.get(blackbox_name)
|
||||||
if model is None:
|
if model is None:
|
||||||
raise ValueError("Invalid Blackbox Type...")
|
raise ValueError("Invalid Blackbox Type...")
|
||||||
return model
|
return model()
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
from injector import inject,singleton
|
from injector import inject,singleton
|
||||||
import yaml
|
import yaml
|
||||||
import sys
|
import sys
|
||||||
@ -101,4 +102,13 @@ class EnvConf():
|
|||||||
def __init__(self, config: Configuration) -> None:
|
def __init__(self, config: Configuration) -> None:
|
||||||
self.version = "0.0.1"
|
self.version = "0.0.1"
|
||||||
self.host = config.get("env.host", default="0.0.0.0")
|
self.host = config.get("env.host", default="0.0.0.0")
|
||||||
self.port = config.get("env.port", default="8080")
|
self.port = config.get("env.port", default="8080")
|
||||||
|
|
||||||
|
@singleton
|
||||||
|
@dataclass
|
||||||
|
class BlackboxConf():
|
||||||
|
lazyloading: bool
|
||||||
|
|
||||||
|
@inject
|
||||||
|
def __init__(self, config: Configuration) -> None:
|
||||||
|
self.lazyloading = bool(config.get("blackbox.lazyloading", default=False))
|
||||||
Reference in New Issue
Block a user