From 60f01a95ea34ffe0063619774df53a3c3daa7be7 Mon Sep 17 00:00:00 2001 From: Roberts Slisans Date: Sat, 10 May 2025 22:35:20 +0300 Subject: [PATCH] Enhanced logger (#502) * add enhanced logging for every startup * add is_model_loaded * fix middleware_log_generation when there is no "text" * Show gr.Info when models are being loaded or unloaded. * Allow users to use React UI together with Gradio auth by specifying GRADIO_AUTH="username:pass" environment variable. --- README.md | 3 +++ installer_scripts/init_app.js | 25 ++++++++++++++---------- installer_scripts/js/initializeApp.js | 1 + react-ui/src/pages/api/gradio/[name].tsx | 4 +++- server.py | 1 + tts_webui/utils/log_generation.py | 5 ++++- tts_webui/utils/manage_model_state.py | 21 ++++++++++++++++---- 7 files changed, 44 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 99309485..496c778c 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ May 10: * Fix missing directory bug causing extensions to fail to load. Thanks Discord/Comstock for discovery of the bug. * Add ACE-Step to React UI. * Add emoji to Gradio UI categories for simplicity. +* Add enhanced logging for every update and app startup, allowing for easier debugging once issues happen. +* Show gr.Info when models are being loaded or unloaded. +* Allow users to use React UI together with Gradio auth by specifying GRADIO_AUTH="username:pass" environment variable. May 7: * Add [Piper TTS](https://github.com/rhasspy/piper) extension diff --git a/installer_scripts/init_app.js b/installer_scripts/init_app.js index 71426809..0bb6dd92 100644 --- a/installer_scripts/init_app.js +++ b/installer_scripts/init_app.js @@ -1,6 +1,6 @@ const fs = require("fs"); const { resolve } = require("path"); -const { $ } = require("./js/shell"); +const { $, $sh } = require("./js/shell"); const { displayError, displayMessage } = require("./js/displayMessage.js"); const { processExit } = require("./js/processExit.js"); const { startServer } = require("./js/server.js"); @@ -11,17 +11,21 @@ const checkConda = async () => { updateState({ status: "checking_dependencies", currentStep: 1 }); displayMessage("Checking conda installation..."); - await $("conda --version"); + await $sh("conda --version"); updateState({ condaReady: true }); displayMessage(""); // verify conda paths - await $("conda info --envs"); + $sh("conda info --envs"); + // expect // # conda environments: // # // base * .. ..\tts-generation-webui-main\installer_files\env + $sh("node --version"); + $sh("python --version"); + $sh("pip --version"); } catch (error) { updateState({ status: "error", lastError: "Conda installation not found" }); @@ -33,7 +37,7 @@ const checkConda = async () => { }; const updateConda = async () => { - await $("conda update -y -n base -c defaults conda"); + await $sh("conda update -y -n base -c defaults conda"); }; const FORCE_REINSTALL = process.env.FORCE_REINSTALL ? true : false; @@ -59,13 +63,13 @@ const syncRepo = async () => { displayMessage("Linking to tts-generation-webui repository"); // this is a clone over the files from https://github.com/rsxdalv/tts-generation-webui try { - await $("git init -b main"); - await $( + await $sh("git init -b main"); + await $sh( "git remote add origin https://github.com/rsxdalv/tts-generation-webui" ); - await $("git fetch"); - await $("git reset --hard origin/main"); // Required when the versioned files existed in path before "git init" of this repo. - await $("git branch --set-upstream-to=origin/main"); + await $sh("git fetch"); + await $sh("git reset --hard origin/main"); // Required when the versioned files existed in path before "git init" of this repo. + await $sh("git branch --set-upstream-to=origin/main"); const newHash = getGitCommitHash(); updateState({ gitHash: newHash }); @@ -83,7 +87,7 @@ const syncRepo = async () => { } else { displayMessage("Pulling updates from tts-generation-webui"); try { - await $("git pull"); + await $sh("git pull"); const newHash = getGitCommitHash(); updateState({ gitHash: newHash }); if (AppliedGitVersion.get() === newHash) { @@ -123,6 +127,7 @@ async function main() { const isUpdated = await syncRepo(); if (!isUpdated) { updateState({ status: "ready", currentStep: 5, totalSteps: 5 }); + $sh("pip show torch torchvision torchaudio"); return true; } diff --git a/installer_scripts/js/initializeApp.js b/installer_scripts/js/initializeApp.js index c30465d9..a92d48fe 100644 --- a/installer_scripts/js/initializeApp.js +++ b/installer_scripts/js/initializeApp.js @@ -304,6 +304,7 @@ const checkIfTorchHasCuda = async () => { exports.repairTorch = async () => { const gpuChoice = readGPUChoice(); + $sh("pip show torch torchvision torchaudio"); if (!checkIfTorchHasCuda() && gpuChoice === "NVIDIA GPU") { displayMessage("Backend is NVIDIA GPU, fixing PyTorch"); try { diff --git a/react-ui/src/pages/api/gradio/[name].tsx b/react-ui/src/pages/api/gradio/[name].tsx index a2a438f6..88db48c1 100644 --- a/react-ui/src/pages/api/gradio/[name].tsx +++ b/react-ui/src/pages/api/gradio/[name].tsx @@ -42,7 +42,9 @@ export default async function handler( res.status(200).json(result); } -const getClient = () => Client.connect(defaultBackend, {}); +const getClient = () => Client.connect(defaultBackend, { + auth: process.env.GRADIO_AUTH?.split(":") as [string, string] | undefined, +}); type GradioChoices = { choices: string[]; diff --git a/server.py b/server.py index 130bdf7e..5fda2a06 100644 --- a/server.py +++ b/server.py @@ -249,6 +249,7 @@ def signal_handler(signal, frame, postgres_process): env={ **os.environ, "GRADIO_BACKEND_AUTOMATIC": f"http://127.0.0.1:{gradio_interface_options['server_port']}/", + # "GRADIO_AUTH": gradio_interface_options["auth"].join(":"), }, shell=True, ) diff --git a/tts_webui/utils/log_generation.py b/tts_webui/utils/log_generation.py index ae78198f..6ebb0342 100644 --- a/tts_webui/utils/log_generation.py +++ b/tts_webui/utils/log_generation.py @@ -16,7 +16,10 @@ def StringifyParams(x): def middleware_log_generation(params: dict): - print("Generating: '''", params["text"], "'''") + text = params.get("text", "") + if text: + text = text[:50] + "..." if len(text) > 50 else text + print(f"Generating: '''{text}'''") print(StringifyParams(params)) diff --git a/tts_webui/utils/manage_model_state.py b/tts_webui/utils/manage_model_state.py index 97374c65..49760699 100644 --- a/tts_webui/utils/manage_model_state.py +++ b/tts_webui/utils/manage_model_state.py @@ -1,6 +1,12 @@ +import gradio as gr from tts_webui.utils.torch_clear_memory import torch_clear_memory +def show(message): + print(message) + gr.Info(message) + + class ModelState: def __init__(self): self._model = None @@ -35,14 +41,14 @@ def wrapper(model_name, *args, **kwargs): model_state = model_states[model_namespace] if not model_state.is_model_loaded(model_name): - print( + show( f"Model '{model_name}' in namespace '{model_namespace}' is not loaded or is different. Loading model..." ) unload_model(model_namespace) model = func(model_name, *args, **kwargs) model_state.set_model(model, model_name) else: - print( + show( f"Using cached model '{model_name}' in namespace '{model_namespace}'." ) @@ -61,9 +67,9 @@ def unload_model(model_namespace): model_states[model_namespace].set_model(None, None) # del model_states[model_namespace] torch_clear_memory() - print(f"Model in namespace '{model_namespace}' has been unloaded.") + show(f"Model in namespace '{model_namespace}' has been unloaded.") else: - print(f"No model loaded in namespace '{model_namespace}'.") + show(f"No model loaded in namespace '{model_namespace}'.") def unload_all_models(): @@ -82,3 +88,10 @@ def list_loaded_models_as_markdown(): lines.append(f"| {namespace} | Not Loaded |") return "\n".join(lines) + + +def is_model_loaded(model_namespace): + return ( + model_namespace in model_states + and model_states[model_namespace].get_model() is not None + )