Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,17 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi.responses import FileResponse
|
| 3 |
import torch
|
| 4 |
import numpy as np
|
| 5 |
import scipy.io.wavfile
|
| 6 |
from transformers import VitsModel, AutoTokenizer
|
| 7 |
import re
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Load your model
|
| 12 |
model = VitsModel.from_pretrained("Somali-tts/somali_tts_model")
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained("saleolow/somali-mms-tts")
|
| 14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
model.to(device)
|
| 16 |
model.eval()
|
| 17 |
|
| 18 |
-
# Number conversion (keep your existing number_words + number_to_words)
|
| 19 |
number_words = {
|
| 20 |
0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
|
| 21 |
6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
|
|
@@ -79,13 +75,20 @@ def normalize_text(text):
|
|
| 79 |
text = text.replace("ZamZam", "SamSam")
|
| 80 |
return text
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
data = await request.json()
|
| 85 |
-
text = normalize_text(data["text"])
|
| 86 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 87 |
with torch.no_grad():
|
| 88 |
waveform = model(**inputs).waveform.squeeze().cpu().numpy()
|
| 89 |
filename = "output.wav"
|
| 90 |
scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
|
| 91 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
import scipy.io.wavfile
|
| 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")
|
| 12 |
model.to(device)
|
| 13 |
model.eval()
|
| 14 |
|
|
|
|
| 15 |
number_words = {
|
| 16 |
0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
|
| 17 |
6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
|
|
|
|
| 75 |
text = text.replace("ZamZam", "SamSam")
|
| 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 |
+
|