don0726 commited on
Commit
d8122e3
Β·
verified Β·
1 Parent(s): 732ba51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -2,38 +2,36 @@ from TTS.api import TTS
2
  import gradio as gr
3
  import os
4
 
5
- MODEL_DIR = "/models/xtts" # βœ… folder, not file
6
-
7
- print("πŸ“‚ Model dir contents:", os.listdir(MODEL_DIR))
8
-
9
-
10
- print(os.listdir("/models"))
11
- print(os.listdir("/models/xtts"))
12
-
13
 
14
  tts = TTS(
15
- model_path=f"{MODEL_DIR}/", # βœ… file path
16
- config_path=f"{MODEL_DIR}/config.json", # βœ… file path
17
  gpu=False
18
  )
19
 
20
- def synthesize(text, speaker_wav):
21
- out_path = "/tmp/out.wav"
 
 
22
  tts.tts_to_file(
23
  text=text,
24
- speaker_wav=speaker_wav,
25
- file_path=out_path,
26
- language="en"
27
  )
28
  return out_path
29
 
30
- demo = gr.Interface(
31
- fn=synthesize,
32
- inputs=[
33
- gr.Textbox(label="Text"),
34
- gr.Audio(type="filepath", label="Voice Sample (10–30 sec)"),
35
- ],
36
- outputs=gr.Audio(type="filepath"),
37
- )
 
 
38
 
39
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
 
2
  import gradio as gr
3
  import os
4
 
5
+ print("πŸ” Loading XTTS model once...")
 
 
 
 
 
 
 
6
 
7
  tts = TTS(
8
+ model_path="/models/xtts/model.pth",
9
+ config_path="/models/xtts/config.json",
10
  gpu=False
11
  )
12
 
13
+ print("βœ… Model loaded!")
14
+
15
+ def generate(text, voice):
16
+ out_path = "out.wav"
17
  tts.tts_to_file(
18
  text=text,
19
+ speaker_wav=voice,
20
+ language="en",
21
+ file_path=out_path
22
  )
23
  return out_path
24
 
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# πŸ”Š XTTS Voice Clone API (HF Space)")
27
+
28
+ text = gr.Textbox(label="Text")
29
+ voice = gr.Audio(type="filepath", label="Upload Voice Sample (WAV)")
30
+
31
+ btn = gr.Button("Generate Voice")
32
+ out = gr.Audio(label="Output Audio")
33
+
34
+ btn.click(generate, inputs=[text, voice], outputs=out)
35
 
36
+ demo.queue()
37
+ demo.launch(server_name="0.0.0.0", server_port=7860)