Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,36 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from TTS.models.vits import VitsModel
|
| 4 |
+
from transformers import AutoTokenizer
|
| 5 |
+
import torchaudio
|
| 6 |
|
| 7 |
+
# Load the model and tokenizer from Hugging Face
|
| 8 |
+
model = VitsModel.from_pretrained("HusseinBashir/codad_tijaabo")
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("HusseinBashir/codad_tijaabo")
|
| 10 |
|
| 11 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 12 |
+
model = model.to(device).eval()
|
| 13 |
|
| 14 |
+
def tts_infer(text):
|
| 15 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 16 |
+
input_ids = inputs.input_ids.to(device)
|
| 17 |
+
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
output = model(input_ids)
|
| 20 |
+
waveform = output["waveform"]
|
| 21 |
+
|
| 22 |
+
# Save or return audio
|
| 23 |
+
sample_rate = 22050 # VITS typically uses 22.05kHz
|
| 24 |
+
torchaudio.save("output.wav", waveform.cpu(), sample_rate)
|
| 25 |
+
return "output.wav"
|
| 26 |
+
|
| 27 |
+
# Create Gradio UI
|
| 28 |
+
interface = gr.Interface(
|
| 29 |
+
fn=tts_infer,
|
| 30 |
+
inputs=gr.Textbox(label="Geli qoraalka aad rabto in cod laga dhigo"),
|
| 31 |
+
outputs=gr.Audio(label="Codka la sameeyey"),
|
| 32 |
+
title="Codad Tijaabo TTS",
|
| 33 |
+
description="Ku qor qoraal Soomaali ah si aad cod u maqasho.",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
interface.launch()
|