Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import scipy.io.wavfile
|
|
| 5 |
from transformers import VitsModel, AutoTokenizer
|
| 6 |
import re
|
| 7 |
|
|
|
|
| 8 |
model = VitsModel.from_pretrained("Somali-tts/somali_tts_model")
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained("saleolow/somali-mms-tts")
|
| 10 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -75,16 +76,19 @@ def normalize_text(text):
|
|
| 75 |
return text
|
| 76 |
|
| 77 |
def tts(text):
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
filename = "output.wav"
|
| 80 |
scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
|
| 81 |
-
return filename
|
| 82 |
|
| 83 |
gr.Interface(
|
| 84 |
fn=tts,
|
| 85 |
inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
|
| 86 |
-
outputs=gr.Audio(
|
| 87 |
title="Somali TTS",
|
| 88 |
-
description="Ku qor qoraal
|
| 89 |
-
).
|
| 90 |
-
|
|
|
|
| 5 |
from transformers import VitsModel, AutoTokenizer
|
| 6 |
import re
|
| 7 |
|
| 8 |
+
# Load fine-tuned model from Hugging Face Hub or local path
|
| 9 |
model = VitsModel.from_pretrained("Somali-tts/somali_tts_model")
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained("saleolow/somali-mms-tts")
|
| 11 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 76 |
return text
|
| 77 |
|
| 78 |
def tts(text):
|
| 79 |
+
text = normalize_text(text)
|
| 80 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
waveform = model(**inputs).waveform.squeeze().cpu().numpy()
|
| 83 |
filename = "output.wav"
|
| 84 |
scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
|
| 85 |
+
return filename
|
| 86 |
|
| 87 |
gr.Interface(
|
| 88 |
fn=tts,
|
| 89 |
inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
|
| 90 |
+
outputs=gr.Audio(label="Codka TTS"),
|
| 91 |
title="Somali TTS",
|
| 92 |
+
description="Ku qor qoraal Soomaaliyeed si aad u maqasho cod dabiici ah.",
|
| 93 |
+
).launch()
|
| 94 |
+
|