Styner1 commited on
Commit
7ba8e71
·
verified ·
1 Parent(s): 17be15c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -33
app.py CHANGED
@@ -1,44 +1,24 @@
1
  import gradio as gr
2
- import os
3
- import traceback
4
- import base64 # Add this
5
  from Zonos_main.tts import ZonosTTS
6
 
7
- # Initialize TTS with error handling
8
- try:
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
- if not text or len(text.strip()) == 0:
18
- raise ValueError("Input text cannot be empty")
19
-
20
- output_path = "/tmp/output.wav"
21
- tts.generate(text, output_path)
22
 
23
- if not os.path.exists(output_path):
24
- raise FileNotFoundError("Audio file was not generated")
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
- traceback.print_exc()
33
- raise gr.Error(f"Audio generation failed: {str(e)}")
34
 
35
- # Gradio interface
36
- demo = gr.Interface(
37
  fn=generate_audio,
38
- inputs=gr.Textbox(label="Input Text", placeholder="Enter text here..."),
39
- outputs=gr.Audio(label="Generated Speech"),
40
- title="Zonos TTS",
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()