Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,12 @@ import scipy.io.wavfile
|
|
| 5 |
from transformers import VitsModel, AutoTokenizer
|
| 6 |
import re
|
| 7 |
|
| 8 |
-
# Load model
|
| 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")
|
| 12 |
model.to(device)
|
| 13 |
model.eval()
|
| 14 |
|
| 15 |
-
# Number words
|
| 16 |
number_words = {
|
| 17 |
0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
|
| 18 |
6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
|
|
@@ -24,7 +22,6 @@ number_words = {
|
|
| 24 |
100: "boqol", 1000: "kun"
|
| 25 |
}
|
| 26 |
|
| 27 |
-
# Number normalization
|
| 28 |
def number_to_words(number):
|
| 29 |
number = int(number)
|
| 30 |
if number < 20:
|
|
@@ -77,7 +74,6 @@ def normalize_text(text):
|
|
| 77 |
text = text.replace("ZamZam", "SamSam")
|
| 78 |
return text
|
| 79 |
|
| 80 |
-
# Text to Speech
|
| 81 |
def tts(text):
|
| 82 |
text = normalize_text(text)
|
| 83 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
|
@@ -85,14 +81,13 @@ def tts(text):
|
|
| 85 |
waveform = model(**inputs).waveform.squeeze().cpu().numpy()
|
| 86 |
filename = "output.wav"
|
| 87 |
scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
|
| 88 |
-
return filename #
|
| 89 |
|
| 90 |
-
#
|
| 91 |
gr.Interface(
|
| 92 |
fn=tts,
|
| 93 |
inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
|
| 94 |
outputs=gr.Audio(type="filepath", label="Codka TTS"),
|
| 95 |
title="Somali TTS",
|
| 96 |
-
description="Ku qor qoraal
|
| 97 |
).queue().launch()
|
| 98 |
-
|
|
|
|
| 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")
|
| 11 |
model.to(device)
|
| 12 |
model.eval()
|
| 13 |
|
|
|
|
| 14 |
number_words = {
|
| 15 |
0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
|
| 16 |
6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
|
|
|
|
| 22 |
100: "boqol", 1000: "kun"
|
| 23 |
}
|
| 24 |
|
|
|
|
| 25 |
def number_to_words(number):
|
| 26 |
number = int(number)
|
| 27 |
if number < 20:
|
|
|
|
| 74 |
text = text.replace("ZamZam", "SamSam")
|
| 75 |
return text
|
| 76 |
|
|
|
|
| 77 |
def tts(text):
|
| 78 |
text = normalize_text(text)
|
| 79 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
|
|
|
| 81 |
waveform = model(**inputs).waveform.squeeze().cpu().numpy()
|
| 82 |
filename = "output.wav"
|
| 83 |
scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
|
| 84 |
+
return filename # let Gradio handle file URL
|
| 85 |
|
| 86 |
+
# ✅ This enables API access!
|
| 87 |
gr.Interface(
|
| 88 |
fn=tts,
|
| 89 |
inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
|
| 90 |
outputs=gr.Audio(type="filepath", label="Codka TTS"),
|
| 91 |
title="Somali TTS",
|
| 92 |
+
description="Ku qor qoraal Soomaali ah si aad u maqasho codka.",
|
| 93 |
).queue().launch()
|
|
|