Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import traceback
|
4 |
-
import base64 # Add this
|
5 |
from Zonos_main.tts import ZonosTTS
|
6 |
|
7 |
-
# Initialize
|
8 |
-
|
9 |
-
tts = ZonosTTS()
|
10 |
-
print("✅ TTS model loaded successfully")
|
11 |
-
except Exception as e:
|
12 |
-
print(f"❌ Model loading failed: {str(e)}")
|
13 |
-
raise
|
14 |
|
15 |
def generate_audio(text):
|
16 |
try:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
output_path = "/tmp/output.wav"
|
21 |
-
tts.generate(text, output_path)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
# Return audio as base64 string
|
27 |
-
with open(output_path, "rb") as audio_file:
|
28 |
-
audio_base64 = base64.b64encode(audio_file.read()).decode('utf-8')
|
29 |
-
return f"data:audio/wav;base64,{audio_base64}"
|
30 |
-
|
31 |
except Exception as e:
|
32 |
-
|
33 |
-
raise gr.Error(f"Audio generation failed: {str(e)}")
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
fn=generate_audio,
|
38 |
-
inputs=gr.Textbox(label="Input
|
39 |
-
outputs=gr.Audio(
|
40 |
-
|
41 |
-
examples=[["Hello world"], ["This is a test"]]
|
42 |
-
)
|
43 |
-
|
44 |
-
demo.launch(show_error=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
import base64
|
|
|
|
|
3 |
from Zonos_main.tts import ZonosTTS
|
4 |
|
5 |
+
# Initialize model ONCE when space starts
|
6 |
+
tts = ZonosTTS() # <-- MUST WORK WITHOUT ERRORS
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def generate_audio(text):
|
9 |
try:
|
10 |
+
# Generate raw audio bytes (MODIFY THIS TO MATCH YOUR MODEL)
|
11 |
+
audio_bytes = tts.generate(text) # Should return bytes directly
|
|
|
|
|
|
|
12 |
|
13 |
+
# Convert to base64
|
14 |
+
return f"data:audio/wav;base64,{base64.b64encode(audio_bytes).decode('utf-8')}"
|
15 |
|
|
|
|
|
|
|
|
|
|
|
16 |
except Exception as e:
|
17 |
+
raise gr.Error(f"TTS Failed: {str(e)}")
|
|
|
18 |
|
19 |
+
# Minimal interface
|
20 |
+
gr.Interface(
|
21 |
fn=generate_audio,
|
22 |
+
inputs=gr.Textbox(label="Input"),
|
23 |
+
outputs=gr.Audio(type="filepath"),
|
24 |
+
).launch()
|
|
|
|
|
|
|
|