Skip to content

Commit

Permalink
Bark TTS lazy load
Browse files Browse the repository at this point in the history
Signed-off-by: bghira <[email protected]>
  • Loading branch information
bghira committed Apr 30, 2023
1 parent 2017e75 commit 2b9f2a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions discord_tron_client/classes/tts/bark/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class BarkRunner:
def __init__(self, bark_driver):
self.driver = bark_driver

def predict(self, prompt, user_config):
try:
if config.is_bark_enabled():
self.driver.load_model()
except Exception as e:
logging.error(f"Could not load Bark driver: {e}")

def predict(self, prompt, user_config):
return self.driver.predict(prompt, user_config)

def usage(self):
Expand Down
5 changes: 5 additions & 0 deletions discord_tron_client/classes/tts/bark/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class BarkTorch:
def __init__(self):
self.loaded = False
self.model = 'Bark'

def details(self):
Expand All @@ -21,6 +22,10 @@ def get_usage(self):
return self.usage or None

def load_model(self):
if self.loaded:
logging.debug(f"Not reloading Bark TTS models.")
return
logging.info(f"Loading Bark TTS model, as it was not already found loaded.")
preload_models()

def _generate(self, prompt, user_config):
Expand Down

0 comments on commit 2b9f2a1

Please sign in to comment.