Improve model initialization and GPU handling in webui.py
Browse files- Add error handling for uninitialized model
- Ensure model is only initialized once
- Add GPU initialization logging
- Prevent redundant model loading
webui.py
CHANGED
@@ -52,8 +52,12 @@ def generate(text,
|
|
52 |
global MODEL
|
53 |
model = MODEL
|
54 |
|
|
|
|
|
|
|
55 |
# if gpu available, move model to gpu
|
56 |
if torch.cuda.is_available():
|
|
|
57 |
model = model.to("cuda")
|
58 |
|
59 |
with torch.no_grad():
|
@@ -111,11 +115,11 @@ def run_tts(
|
|
111 |
|
112 |
def build_ui(model_dir, device=0):
|
113 |
|
114 |
-
# Initialize model
|
115 |
-
model = initialize_model(model_dir, device=device)
|
116 |
-
|
117 |
global MODEL
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
# Define callback function for voice cloning
|
121 |
def voice_clone(text, prompt_text, prompt_wav_upload, prompt_wav_record):
|
|
|
52 |
global MODEL
|
53 |
model = MODEL
|
54 |
|
55 |
+
if model is None:
|
56 |
+
raise RuntimeError("Model not initialized. Please ensure the model is loaded before generating audio.")
|
57 |
+
|
58 |
# if gpu available, move model to gpu
|
59 |
if torch.cuda.is_available():
|
60 |
+
print("Moving model to GPU")
|
61 |
model = model.to("cuda")
|
62 |
|
63 |
with torch.no_grad():
|
|
|
115 |
|
116 |
def build_ui(model_dir, device=0):
|
117 |
|
|
|
|
|
|
|
118 |
global MODEL
|
119 |
+
|
120 |
+
# Initialize model
|
121 |
+
if MODEL is None:
|
122 |
+
MODEL = initialize_model(model_dir, device=device)
|
123 |
|
124 |
# Define callback function for voice cloning
|
125 |
def voice_clone(text, prompt_text, prompt_wav_upload, prompt_wav_record):
|