Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, VitsModel
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load model iyo tokenizer
|
| 7 |
+
model_name = "jellecali8/somali_tts_model" # beddel hadii magaca repo-gaagu kala duwanaado
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = VitsModel.from_pretrained(model_name).to("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
+
|
| 11 |
+
def tts(text):
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 13 |
+
inputs = {k: v.to(model.device) for k, v in inputs.items()}
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
# Halkan waa inaad ku beddeshaa sida output audio laga helayo, waayo VitsModel ma soo saaro waveform toos ah
|
| 17 |
+
# Haddii aad haysato vocoder model, ku socodsii spectrogram outputs-ka halkaas
|
| 18 |
+
# Tusaalaha hoose waa placeholder:
|
| 19 |
+
audio = np.zeros(16000) # 1 second of silence (sample rate 16k)
|
| 20 |
+
return (16000, audio)
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(fn=tts,
|
| 23 |
+
inputs=gr.Textbox(lines=2, placeholder="Ku qor qoraalka Somali..."),
|
| 24 |
+
outputs=gr.Audio(type="numpy"))
|
| 25 |
+
|
| 26 |
+
demo.launch()
|