don0726 commited on
Commit
3f9ecf2
Β·
verified Β·
1 Parent(s): bcae1c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -5,7 +5,7 @@ from TTS.api import TTS
5
 
6
  print("πŸ” Loading XTTS model once...")
7
 
8
- # Auto-accept Coqui license (required for HF Spaces)
9
  os.environ["COQUI_TOS_AGREED"] = "1"
10
 
11
  tts = TTS(
@@ -17,11 +17,8 @@ tts = TTS(
17
  print("βœ… Model loaded!")
18
 
19
  def synthesize(text, speaker_wav):
20
- if not text:
21
- return None
22
-
23
- if speaker_wav is None:
24
- raise gr.Error("Please upload a speaker WAV (5–10 seconds clean voice).")
25
 
26
  out_path = os.path.join(tempfile.gettempdir(), "out.wav")
27
 
@@ -35,22 +32,17 @@ def synthesize(text, speaker_wav):
35
  return out_path
36
 
37
 
38
- with gr.Blocks(title="XTTS Voice Clone API") as demo:
39
- gr.Markdown("## πŸ—£οΈ XTTS Voice Cloning API (Offline, HF Space)")
40
- gr.Markdown("Upload 5–10 seconds clean voice sample + enter text.")
41
-
42
- text = gr.Textbox(label="Text", placeholder="Type something...")
43
- speaker = gr.Audio(label="Speaker WAV (5–10s clean voice)", type="filepath")
44
- out_audio = gr.Audio(label="Generated Voice", type="filepath")
45
-
46
- btn = gr.Button("Submit")
47
-
48
- btn.click(
49
- fn=synthesize,
50
- inputs=[text, speaker],
51
- outputs=out_audio,
52
- api_name="tts" # <-- IMPORTANT: exposes /tts endpoint
53
- )
54
 
55
- # HF Spaces auto handles server + port
56
- demo.queue().launch()
 
5
 
6
  print("πŸ” Loading XTTS model once...")
7
 
8
+ # Accept Coqui license automatically
9
  os.environ["COQUI_TOS_AGREED"] = "1"
10
 
11
  tts = TTS(
 
17
  print("βœ… Model loaded!")
18
 
19
  def synthesize(text, speaker_wav):
20
+ if not text or speaker_wav is None:
21
+ raise gr.Error("Please provide both text and speaker WAV.")
 
 
 
22
 
23
  out_path = os.path.join(tempfile.gettempdir(), "out.wav")
24
 
 
32
  return out_path
33
 
34
 
35
+ demo = gr.Interface(
36
+ fn=synthesize,
37
+ inputs=[
38
+ gr.Textbox(label="Text"),
39
+ gr.Audio(label="Speaker WAV (5–10s clean voice)", type="filepath"),
40
+ ],
41
+ outputs=gr.Audio(label="Generated Voice", type="filepath"),
42
+ title="XTTS Voice Cloning API (Offline, HF Space)",
43
+ description="Upload 5–10 seconds clean voice sample + enter text.",
44
+ api_name="tts" # βœ… THIS FIXES 'No API found'
45
+ )
 
 
 
 
 
46
 
47
+ demo.queue()
48
+ demo.launch()