Spaces:
Sleeping
Sleeping
Commit Β·
8820ba4
1
Parent(s): f150896
Fix model loading error handling and lambda function warnings
Browse files- Add better error handling for TTS model loading with alternative methods
- Fix lambda function warnings by using proper function factory
- Update requirements.txt to constrain Gradio version
- app.py +47 -10
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -13,12 +13,39 @@ from pathlib import Path
|
|
| 13 |
MODEL_NAME = "ashishkblink/vakya"
|
| 14 |
|
| 15 |
print("π Loading Vakya TTS model...")
|
|
|
|
| 16 |
try:
|
| 17 |
-
|
|
|
|
| 18 |
print("β
Model loaded successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
print(f"β Error loading model: {e}")
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Supported languages for Indian languages
|
| 24 |
INDIAN_LANGUAGES = {
|
|
@@ -189,26 +216,36 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
| 189 |
# Examples section
|
| 190 |
gr.Markdown("### π Example Texts (Click to use)")
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
with gr.Row():
|
| 193 |
for lang_name, lang_code in list(INDIAN_LANGUAGES.items())[:5]:
|
| 194 |
example_text = EXAMPLE_TEXTS.get(lang_code, "")
|
| 195 |
-
gr.Button(
|
| 196 |
f"{lang_name} Example",
|
| 197 |
size="sm"
|
| 198 |
-
)
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
| 201 |
)
|
| 202 |
|
| 203 |
with gr.Row():
|
| 204 |
for lang_name, lang_code in list(INDIAN_LANGUAGES.items())[5:]:
|
| 205 |
example_text = EXAMPLE_TEXTS.get(lang_code, "")
|
| 206 |
-
gr.Button(
|
| 207 |
f"{lang_name} Example",
|
| 208 |
size="sm"
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
| 212 |
)
|
| 213 |
|
| 214 |
# Footer
|
|
|
|
| 13 |
MODEL_NAME = "ashishkblink/vakya"
|
| 14 |
|
| 15 |
print("π Loading Vakya TTS model...")
|
| 16 |
+
tts = None
|
| 17 |
try:
|
| 18 |
+
# Try loading with explicit model name
|
| 19 |
+
tts = TTS(model_name=MODEL_NAME, progress_bar=True)
|
| 20 |
print("β
Model loaded successfully!")
|
| 21 |
+
except ValueError as e:
|
| 22 |
+
# This might be the unpacking error - try with explicit model type
|
| 23 |
+
print(f"β οΈ Initial load failed (ValueError): {e}")
|
| 24 |
+
print("π Trying with explicit model type...")
|
| 25 |
+
try:
|
| 26 |
+
# XTTS models might need explicit specification
|
| 27 |
+
tts = TTS(model_name=MODEL_NAME, model_type="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=True)
|
| 28 |
+
print("β
Model loaded successfully with explicit type!")
|
| 29 |
+
except Exception as e2:
|
| 30 |
+
print(f"β Explicit type loading failed: {e2}")
|
| 31 |
+
import traceback
|
| 32 |
+
traceback.print_exc()
|
| 33 |
+
tts = None
|
| 34 |
except Exception as e:
|
| 35 |
print(f"β Error loading model: {e}")
|
| 36 |
+
import traceback
|
| 37 |
+
traceback.print_exc()
|
| 38 |
+
# Try alternative initialization methods
|
| 39 |
+
try:
|
| 40 |
+
print("π Trying alternative model loading method...")
|
| 41 |
+
# Try with gpu parameter explicitly set
|
| 42 |
+
tts = TTS(model_name=MODEL_NAME, gpu=False, progress_bar=True)
|
| 43 |
+
print("β
Model loaded successfully with alternative method!")
|
| 44 |
+
except Exception as e2:
|
| 45 |
+
print(f"β Alternative loading also failed: {e2}")
|
| 46 |
+
import traceback
|
| 47 |
+
traceback.print_exc()
|
| 48 |
+
tts = None
|
| 49 |
|
| 50 |
# Supported languages for Indian languages
|
| 51 |
INDIAN_LANGUAGES = {
|
|
|
|
| 216 |
# Examples section
|
| 217 |
gr.Markdown("### π Example Texts (Click to use)")
|
| 218 |
|
| 219 |
+
def make_example_loader(example_text, lang_name):
|
| 220 |
+
"""Create a function to load example text and language"""
|
| 221 |
+
def load_example():
|
| 222 |
+
return example_text, lang_name
|
| 223 |
+
return load_example
|
| 224 |
+
|
| 225 |
with gr.Row():
|
| 226 |
for lang_name, lang_code in list(INDIAN_LANGUAGES.items())[:5]:
|
| 227 |
example_text = EXAMPLE_TEXTS.get(lang_code, "")
|
| 228 |
+
example_btn = gr.Button(
|
| 229 |
f"{lang_name} Example",
|
| 230 |
size="sm"
|
| 231 |
+
)
|
| 232 |
+
example_btn.click(
|
| 233 |
+
fn=make_example_loader(example_text, lang_name),
|
| 234 |
+
outputs=[text_input, language_dropdown],
|
| 235 |
+
api_name=f"load_example_{lang_name.lower().replace(' ', '_')}"
|
| 236 |
)
|
| 237 |
|
| 238 |
with gr.Row():
|
| 239 |
for lang_name, lang_code in list(INDIAN_LANGUAGES.items())[5:]:
|
| 240 |
example_text = EXAMPLE_TEXTS.get(lang_code, "")
|
| 241 |
+
example_btn = gr.Button(
|
| 242 |
f"{lang_name} Example",
|
| 243 |
size="sm"
|
| 244 |
+
)
|
| 245 |
+
example_btn.click(
|
| 246 |
+
fn=make_example_loader(example_text, lang_name),
|
| 247 |
+
outputs=[text_input, language_dropdown],
|
| 248 |
+
api_name=f"load_example_{lang_name.lower().replace(' ', '_')}"
|
| 249 |
)
|
| 250 |
|
| 251 |
# Footer
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
TTS>=0.22.0
|
| 2 |
-
gradio>=4.0.0
|
| 3 |
torch>=2.0.0
|
| 4 |
torchaudio>=2.0.0
|
| 5 |
numpy>=1.21.0
|
|
|
|
| 1 |
TTS>=0.22.0
|
| 2 |
+
gradio>=4.0.0,<5.0.0
|
| 3 |
torch>=2.0.0
|
| 4 |
torchaudio>=2.0.0
|
| 5 |
numpy>=1.21.0
|