Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
-
import sciimport gradio as gr
|
| 5 |
-
import torch
|
| 6 |
-
import numpy as np
|
| 7 |
-
import tempfile
|
| 8 |
import scipy.io.wavfile
|
| 9 |
from transformers import VitsModel, AutoTokenizer
|
| 10 |
-
|
| 11 |
-
# Load model and tokenizer
|
| 12 |
-
model = VitsModel.from_pretrained("jellecali8/somali_tts_model")
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-som")
|
| 14 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
-
model.to(device).eval()
|
| 16 |
-
|
| 17 |
-
# Load custom speaker embedding
|
| 18 |
-
try:
|
| 19 |
-
speaker_embedding = torch.tensor(np.load("new_speaker_embedding.npy")).unsqueeze(0).to(device)
|
| 20 |
-
except Exception as e:
|
| 21 |
-
speaker_embedding = None
|
| 22 |
-
print(f"Embedding load error: {e}")
|
| 23 |
-
|
| 24 |
-
def tts_fn(text):
|
| 25 |
-
try:
|
| 26 |
-
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 27 |
-
|
| 28 |
-
with torch.no_grad():
|
| 29 |
-
output = model(**inputs, speaker_embeddings=speaker_embedding)
|
| 30 |
-
|
| 31 |
-
# Check for empty waveform
|
| 32 |
-
if output.waveform is None or output.waveform.shape[-1] == 0:
|
| 33 |
-
return "❌ Model-ka ma soo saarin cod. Waxaa laga yaabaa in embedding uu cilad leeyahay."
|
| 34 |
-
|
| 35 |
-
audio = output.waveform.squeeze().cpu().numpy()
|
| 36 |
-
|
| 37 |
-
# Save audio to temp file
|
| 38 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
|
| 39 |
-
scipy.io.wavfile.write(f.name, rate=16000, data=(audio * 32767).astype(np.int16))
|
| 40 |
-
return f.name
|
| 41 |
-
except Exception as e:
|
| 42 |
-
return f"Error during synthesis: {str(e)}"
|
| 43 |
-
|
| 44 |
-
gr.Interface(
|
| 45 |
-
fn=tts_fn,
|
| 46 |
-
inputs=gr.Textbox(label="Qor qoraalka Somali"),
|
| 47 |
-
outputs=gr.Audio(label="Codka la clone gareeyey"),
|
| 48 |
-
title="Cod Somali ah oo la clone gareeyay"
|
| 49 |
-
).launch()
|
| 50 |
-
py.io.wavfile
|
| 51 |
-
from transformers import VitsModel, AutoTokenizer
|
| 52 |
import re
|
| 53 |
|
| 54 |
# Load model and tokenizer
|
|
|
|
| 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 model and tokenizer
|