Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import
|
4 |
from Zonos_main.tts import ZonosTTS # Adjust import path as needed
|
5 |
|
6 |
-
# Initialize TTS
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def generate_audio(text):
|
10 |
try:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
tts.generate(text, output_path)
|
16 |
|
17 |
-
|
|
|
|
|
18 |
return output_path
|
19 |
except Exception as e:
|
|
|
20 |
raise gr.Error(f"Audio generation failed: {str(e)}")
|
21 |
|
22 |
-
#
|
23 |
demo = gr.Interface(
|
24 |
fn=generate_audio,
|
25 |
-
inputs=gr.Textbox(label="Input Text"),
|
26 |
outputs=gr.Audio(label="Generated Speech"),
|
27 |
-
title="Zonos TTS
|
28 |
-
|
29 |
)
|
30 |
|
31 |
-
|
32 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import traceback
|
4 |
from Zonos_main.tts import ZonosTTS # Adjust import path as needed
|
5 |
|
6 |
+
# Initialize TTS with error handling
|
7 |
+
try:
|
8 |
+
tts = ZonosTTS()
|
9 |
+
print("✅ TTS model loaded successfully")
|
10 |
+
except Exception as e:
|
11 |
+
print(f"❌ Model loading failed: {str(e)}")
|
12 |
+
raise
|
13 |
|
14 |
def generate_audio(text):
|
15 |
try:
|
16 |
+
if not text or len(text.strip()) == 0:
|
17 |
+
raise ValueError("Input text cannot be empty")
|
18 |
+
|
19 |
+
output_path = "/tmp/output.wav"
|
20 |
tts.generate(text, output_path)
|
21 |
|
22 |
+
if not os.path.exists(output_path):
|
23 |
+
raise FileNotFoundError("Audio file was not generated")
|
24 |
+
|
25 |
return output_path
|
26 |
except Exception as e:
|
27 |
+
traceback.print_exc()
|
28 |
raise gr.Error(f"Audio generation failed: {str(e)}")
|
29 |
|
30 |
+
# Gradio interface
|
31 |
demo = gr.Interface(
|
32 |
fn=generate_audio,
|
33 |
+
inputs=gr.Textbox(label="Input Text", placeholder="Enter text here..."),
|
34 |
outputs=gr.Audio(label="Generated Speech"),
|
35 |
+
title="Zonos TTS",
|
36 |
+
examples=[["Hello world"], ["This is a test"]]
|
37 |
)
|
38 |
|
39 |
+
demo.launch(show_error=True)
|
|