Added gradio app
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import VitsModel, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
import tempfile
|
| 5 |
+
import scipy.io.wavfile
|
| 6 |
+
|
| 7 |
+
# Load model and tokenizer
|
| 8 |
+
model = VitsModel.from_pretrained("facebook/mms-tts-sag")
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-sag")
|
| 10 |
+
|
| 11 |
+
# Text-to-speech function
|
| 12 |
+
def tts_sango(text):
|
| 13 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**inputs).waveform[0]
|
| 16 |
+
# Save waveform to a temporary .wav file
|
| 17 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
| 18 |
+
scipy.io.wavfile.write(f.name, model.config.sampling_rate, output.numpy())
|
| 19 |
+
return f.name
|
| 20 |
+
|
| 21 |
+
# Gradio interface
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=tts_sango,
|
| 24 |
+
inputs=gr.Textbox(label="Enter Sango Text"),
|
| 25 |
+
outputs=gr.Audio(label="Generated Audio"),
|
| 26 |
+
title="Sango TTS with MMS",
|
| 27 |
+
description="Text-to-Speech using Facebook's MMS model for Sango language"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|