Spaces:
Runtime error
Runtime error
Commit
·
ceb6264
1
Parent(s):
63ef4fe
changed3 app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,38 @@
|
|
| 1 |
import json
|
| 2 |
-
import
|
| 3 |
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
-
from TTS.
|
| 7 |
|
| 8 |
# ---------- Paths ----------
|
| 9 |
-
MODEL_PATH = "checkpoint_80000.pth"
|
| 10 |
CONFIG_PATH = "config.json"
|
| 11 |
|
| 12 |
-
|
| 13 |
-
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
| 14 |
-
cfg = json.load(f)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
# ---------- Inference function ----------
|
| 26 |
def tts_generate(text: str):
|
| 27 |
-
|
|
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
wav =
|
| 32 |
|
| 33 |
-
#
|
| 34 |
wav = np.asarray(wav, dtype="float32").flatten()
|
| 35 |
|
| 36 |
# Gradio Audio(type="numpy") expects (sample_rate, np.ndarray)
|
|
@@ -41,15 +43,15 @@ demo = gr.Interface(
|
|
| 41 |
fn=tts_generate,
|
| 42 |
inputs=gr.Textbox(
|
| 43 |
label="Input text",
|
| 44 |
-
placeholder="Type Sinhala text here…
|
| 45 |
lines=3,
|
| 46 |
),
|
| 47 |
outputs=gr.Audio(
|
| 48 |
label="Generated speech",
|
| 49 |
type="numpy",
|
| 50 |
),
|
| 51 |
-
title="Sinhala TTS",
|
| 52 |
-
description="Sinhala TTS model
|
| 53 |
)
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
+
from TTS.api import TTS
|
| 7 |
|
| 8 |
# ---------- Paths ----------
|
| 9 |
+
MODEL_PATH = "checkpoint_80000.pth" # or checkpoint_70000.pth if that's the good one
|
| 10 |
CONFIG_PATH = "config.json"
|
| 11 |
|
| 12 |
+
run_dir = Path(".")
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# ---------- Load model ----------
|
| 15 |
+
# In Spaces we will force CPU (gpu=False)
|
| 16 |
+
tts = TTS(
|
| 17 |
+
model_path=str(run_dir / MODEL_PATH),
|
| 18 |
+
config_path=str(run_dir / CONFIG_PATH),
|
| 19 |
+
progress_bar=False,
|
| 20 |
+
gpu=False,
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Sample rate from the loaded synthesizer
|
| 24 |
+
SAMPLE_RATE = tts.synthesizer.output_sample_rate
|
| 25 |
+
|
| 26 |
# ---------- Inference function ----------
|
| 27 |
def tts_generate(text: str):
|
| 28 |
+
text = text.strip()
|
| 29 |
+
if not text:
|
| 30 |
return None
|
| 31 |
|
| 32 |
+
# This is the same as your local script
|
| 33 |
+
wav = tts.tts(text)
|
| 34 |
|
| 35 |
+
# Ensure numpy array (1D) for Gradio
|
| 36 |
wav = np.asarray(wav, dtype="float32").flatten()
|
| 37 |
|
| 38 |
# Gradio Audio(type="numpy") expects (sample_rate, np.ndarray)
|
|
|
|
| 43 |
fn=tts_generate,
|
| 44 |
inputs=gr.Textbox(
|
| 45 |
label="Input text",
|
| 46 |
+
placeholder="Type Sinhala text here…",
|
| 47 |
lines=3,
|
| 48 |
),
|
| 49 |
outputs=gr.Audio(
|
| 50 |
label="Generated speech",
|
| 51 |
type="numpy",
|
| 52 |
),
|
| 53 |
+
title="Sinhala TTS ",
|
| 54 |
+
description="Sinhala TTS model research-stage model.",
|
| 55 |
)
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|