Styner1 commited on
Commit
b77adfe
·
verified ·
1 Parent(s): de3d52f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -1,32 +1,39 @@
1
  import gradio as gr
2
  import os
3
- import sys
4
  from Zonos_main.tts import ZonosTTS # Adjust import path as needed
5
 
6
- # Initialize TTS model
7
- tts = ZonosTTS()
 
 
 
 
 
8
 
9
  def generate_audio(text):
10
  try:
11
- # Generate audio file path
12
- output_path = "output.wav"
13
-
14
- # Run TTS
15
  tts.generate(text, output_path)
16
 
17
- # Return audio file
 
 
18
  return output_path
19
  except Exception as e:
 
20
  raise gr.Error(f"Audio generation failed: {str(e)}")
21
 
22
- # Create Gradio interface
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 Service",
28
- description="Convert text to speech using Zonos TTS model"
29
  )
30
 
31
- # Launch the app
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)