From 95600073bcd0430d2195bd82e09d82398455ae03 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 19 Dec 2023 20:20:45 -0800 Subject: [PATCH] Add an informative error when extension requirements are missing --- extensions/coqui_tts/script.py | 17 ++--------------- modules/extensions.py | 7 ++++++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/extensions/coqui_tts/script.py b/extensions/coqui_tts/script.py index 8eab7afb..3b241c58 100644 --- a/extensions/coqui_tts/script.py +++ b/extensions/coqui_tts/script.py @@ -6,27 +6,14 @@ import time from pathlib import Path import gradio as gr +from TTS.api import TTS +from TTS.utils.synthesizer import Synthesizer from modules import chat, shared, ui_chat from modules.logging_colors import logger from modules.ui import create_refresh_button from modules.utils import gradio -try: - from TTS.api import TTS - from TTS.utils.synthesizer import Synthesizer -except ModuleNotFoundError: - logger.error( - "Could not find the TTS module. Make sure to install the requirements for the coqui_tts extension." - "\n" - "\nLinux / Mac:\npip install -r extensions/coqui_tts/requirements.txt\n" - "\nWindows:\npip install -r extensions\\coqui_tts\\requirements.txt\n" - "\n" - "If you used the one-click installer, paste the command above in the terminal window launched after running the \"cmd_\" script. On Windows, that's \"cmd_windows.bat\"." - ) - - raise - os.environ["COQUI_TOS_AGREED"] = "1" params = { diff --git a/modules/extensions.py b/modules/extensions.py index 6c072504..25fcc0a3 100644 --- a/modules/extensions.py +++ b/modules/extensions.py @@ -33,7 +33,12 @@ def load_extensions(): if name != 'api': logger.info(f'Loading the extension "{name}"...') try: - exec(f"import extensions.{name}.script") + try: + exec(f"import extensions.{name}.script") + except ModuleNotFoundError: + logger.error(f"Could not import the requirements for '{name}'. Make sure to install the requirements for the extension.\n\nLinux / Mac:\n\npip install -r extensions/{name}/requirements.txt --upgrade\n\nWindows:\n\npip install -r extensions\\{name}\\requirements.txt --upgrade\n\nIf you used the one-click installer, paste the command above in the terminal window opened after launching the cmd script for your OS.") + raise + extension = getattr(extensions, name).script apply_settings(extension, name) if extension not in setup_called and hasattr(extension, "setup"):