Skip to content

Commit 60f01a9

Browse files
authored
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.
1 parent cc1a179 commit 60f01a9

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ May 10:
8787
* Fix missing directory bug causing extensions to fail to load. Thanks Discord/Comstock for discovery of the bug.
8888
* Add ACE-Step to React UI.
8989
* Add emoji to Gradio UI categories for simplicity.
90+
* Add enhanced logging for every update and app startup, allowing for easier debugging once issues happen.
91+
* Show gr.Info when models are being loaded or unloaded.
92+
* Allow users to use React UI together with Gradio auth by specifying GRADIO_AUTH="username:pass" environment variable.
9093

9194
May 7:
9295
* Add [Piper TTS](https://github.com/rhasspy/piper) extension

installer_scripts/init_app.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22
const { resolve } = require("path");
3-
const { $ } = require("./js/shell");
3+
const { $, $sh } = require("./js/shell");
44
const { displayError, displayMessage } = require("./js/displayMessage.js");
55
const { processExit } = require("./js/processExit.js");
66
const { startServer } = require("./js/server.js");
@@ -11,17 +11,21 @@ const checkConda = async () => {
1111
updateState({ status: "checking_dependencies", currentStep: 1 });
1212

1313
displayMessage("Checking conda installation...");
14-
await $("conda --version");
14+
await $sh("conda --version");
1515

1616
updateState({ condaReady: true });
1717

1818
displayMessage("");
1919
// verify conda paths
20-
await $("conda info --envs");
20+
$sh("conda info --envs");
21+
2122
// expect
2223
// # conda environments:
2324
// #
2425
// base * .. ..\tts-generation-webui-main\installer_files\env
26+
$sh("node --version");
27+
$sh("python --version");
28+
$sh("pip --version");
2529
} catch (error) {
2630
updateState({ status: "error", lastError: "Conda installation not found" });
2731

@@ -33,7 +37,7 @@ const checkConda = async () => {
3337
};
3438

3539
const updateConda = async () => {
36-
await $("conda update -y -n base -c defaults conda");
40+
await $sh("conda update -y -n base -c defaults conda");
3741
};
3842

3943
const FORCE_REINSTALL = process.env.FORCE_REINSTALL ? true : false;
@@ -59,13 +63,13 @@ const syncRepo = async () => {
5963
displayMessage("Linking to tts-generation-webui repository");
6064
// this is a clone over the files from https://github.com/rsxdalv/tts-generation-webui
6165
try {
62-
await $("git init -b main");
63-
await $(
66+
await $sh("git init -b main");
67+
await $sh(
6468
"git remote add origin https://github.com/rsxdalv/tts-generation-webui"
6569
);
66-
await $("git fetch");
67-
await $("git reset --hard origin/main"); // Required when the versioned files existed in path before "git init" of this repo.
68-
await $("git branch --set-upstream-to=origin/main");
70+
await $sh("git fetch");
71+
await $sh("git reset --hard origin/main"); // Required when the versioned files existed in path before "git init" of this repo.
72+
await $sh("git branch --set-upstream-to=origin/main");
6973

7074
const newHash = getGitCommitHash();
7175
updateState({ gitHash: newHash });
@@ -83,7 +87,7 @@ const syncRepo = async () => {
8387
} else {
8488
displayMessage("Pulling updates from tts-generation-webui");
8589
try {
86-
await $("git pull");
90+
await $sh("git pull");
8791
const newHash = getGitCommitHash();
8892
updateState({ gitHash: newHash });
8993
if (AppliedGitVersion.get() === newHash) {
@@ -123,6 +127,7 @@ async function main() {
123127
const isUpdated = await syncRepo();
124128
if (!isUpdated) {
125129
updateState({ status: "ready", currentStep: 5, totalSteps: 5 });
130+
$sh("pip show torch torchvision torchaudio");
126131
return true;
127132
}
128133

installer_scripts/js/initializeApp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ const checkIfTorchHasCuda = async () => {
304304

305305
exports.repairTorch = async () => {
306306
const gpuChoice = readGPUChoice();
307+
$sh("pip show torch torchvision torchaudio");
307308
if (!checkIfTorchHasCuda() && gpuChoice === "NVIDIA GPU") {
308309
displayMessage("Backend is NVIDIA GPU, fixing PyTorch");
309310
try {

react-ui/src/pages/api/gradio/[name].tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export default async function handler(
4242
res.status(200).json(result);
4343
}
4444

45-
const getClient = () => Client.connect(defaultBackend, {});
45+
const getClient = () => Client.connect(defaultBackend, {
46+
auth: process.env.GRADIO_AUTH?.split(":") as [string, string] | undefined,
47+
});
4648

4749
type GradioChoices = {
4850
choices: string[];

server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def signal_handler(signal, frame, postgres_process):
249249
env={
250250
**os.environ,
251251
"GRADIO_BACKEND_AUTOMATIC": f"http://127.0.0.1:{gradio_interface_options['server_port']}/",
252+
# "GRADIO_AUTH": gradio_interface_options["auth"].join(":"),
252253
},
253254
shell=True,
254255
)

tts_webui/utils/log_generation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def StringifyParams(x):
1616

1717

1818
def middleware_log_generation(params: dict):
19-
print("Generating: '''", params["text"], "'''")
19+
text = params.get("text", "")
20+
if text:
21+
text = text[:50] + "..." if len(text) > 50 else text
22+
print(f"Generating: '''{text}'''")
2023
print(StringifyParams(params))
2124

2225

tts_webui/utils/manage_model_state.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import gradio as gr
12
from tts_webui.utils.torch_clear_memory import torch_clear_memory
23

34

5+
def show(message):
6+
print(message)
7+
gr.Info(message)
8+
9+
410
class ModelState:
511
def __init__(self):
612
self._model = None
@@ -35,14 +41,14 @@ def wrapper(model_name, *args, **kwargs):
3541
model_state = model_states[model_namespace]
3642

3743
if not model_state.is_model_loaded(model_name):
38-
print(
44+
show(
3945
f"Model '{model_name}' in namespace '{model_namespace}' is not loaded or is different. Loading model..."
4046
)
4147
unload_model(model_namespace)
4248
model = func(model_name, *args, **kwargs)
4349
model_state.set_model(model, model_name)
4450
else:
45-
print(
51+
show(
4652
f"Using cached model '{model_name}' in namespace '{model_namespace}'."
4753
)
4854

@@ -61,9 +67,9 @@ def unload_model(model_namespace):
6167
model_states[model_namespace].set_model(None, None)
6268
# del model_states[model_namespace]
6369
torch_clear_memory()
64-
print(f"Model in namespace '{model_namespace}' has been unloaded.")
70+
show(f"Model in namespace '{model_namespace}' has been unloaded.")
6571
else:
66-
print(f"No model loaded in namespace '{model_namespace}'.")
72+
show(f"No model loaded in namespace '{model_namespace}'.")
6773

6874

6975
def unload_all_models():
@@ -82,3 +88,10 @@ def list_loaded_models_as_markdown():
8288
lines.append(f"| {namespace} | Not Loaded |")
8389

8490
return "\n".join(lines)
91+
92+
93+
def is_model_loaded(model_namespace):
94+
return (
95+
model_namespace in model_states
96+
and model_states[model_namespace].get_model() is not None
97+
)

0 commit comments

Comments
 (0)