Rodri359 commited on
Commit ·
b4eca84
1
Parent(s): 66f8cff
Add application file
Browse files- app.py +38 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
from transformers import VitsModel, AutoTokenizer
|
| 5 |
+
|
| 6 |
+
# Configuración del modelo
|
| 7 |
+
model_id = "facebook/mms-tts-yua"
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
|
| 10 |
+
print(f"Cargando modelo en: {device}")
|
| 11 |
+
model = VitsModel.from_pretrained(model_id).to(device)
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 13 |
+
|
| 14 |
+
def generate_tts(text):
|
| 15 |
+
if not text.strip():
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 19 |
+
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
output = model(**inputs)
|
| 22 |
+
|
| 23 |
+
waveform = output.waveform[0].cpu().numpy()
|
| 24 |
+
sample_rate = model.config.sampling_rate
|
| 25 |
+
|
| 26 |
+
return (sample_rate, waveform)
|
| 27 |
+
|
| 28 |
+
# Interfaz de Gradio
|
| 29 |
+
demo = gr.Interface(
|
| 30 |
+
fn=generate_tts,
|
| 31 |
+
inputs=gr.Textbox(label="Escribe en Maya Yucateco", placeholder="Bix yanilech..."),
|
| 32 |
+
outputs=gr.Audio(label="Audio Generado"),
|
| 33 |
+
title="Maya Yucateco TTS (Facebook MMS)",
|
| 34 |
+
description="Servidor de síntesis de voz para el idioma Maya Yucateco."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
accelerate
|
| 3 |
+
torch
|
| 4 |
+
scipy
|
| 5 |
+
numpy
|