Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import torch
|
|
4 |
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
|
5 |
from huggingface_hub import login
|
6 |
|
7 |
-
|
8 |
# Obtener el token desde las variables de entorno
|
9 |
hf_token = os.getenv("HF_TOKEN")
|
10 |
if hf_token is None:
|
@@ -14,9 +13,14 @@ if hf_token is None:
|
|
14 |
login(hf_token)
|
15 |
|
16 |
# Intentar cargar el modelo
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
try:
|
18 |
-
models, cfg, task = load_model_ensemble_and_task_from_hf_hub("
|
19 |
-
)
|
20 |
if not models:
|
21 |
raise RuntimeError("No se pudo cargar el modelo. Asegúrate de que el nombre del modelo es correcto y que está disponible en Hugging Face Hub.")
|
22 |
model = models[0]
|
@@ -25,24 +29,28 @@ except Exception as e:
|
|
25 |
|
26 |
# Función para generar la salida de texto a voz
|
27 |
def text_to_speech(text):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
# Crear interfaz de Gradio
|
40 |
iface = gr.Interface(
|
41 |
fn=text_to_speech,
|
42 |
inputs=gr.inputs.Textbox(lines=2, placeholder="Ingrese el texto aquí..."),
|
43 |
-
outputs=gr.outputs.Audio(type="numpy", label="Output Audio")
|
|
|
|
|
44 |
)
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
iface.launch()
|
48 |
-
add_to_git_credential=True
|
|
|
4 |
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
|
5 |
from huggingface_hub import login
|
6 |
|
|
|
7 |
# Obtener el token desde las variables de entorno
|
8 |
hf_token = os.getenv("HF_TOKEN")
|
9 |
if hf_token is None:
|
|
|
13 |
login(hf_token)
|
14 |
|
15 |
# Intentar cargar el modelo
|
16 |
+
|
17 |
+
# Load model directly
|
18 |
+
processor = AutoProcessor.from_pretrained("ovieyra21/es_speecht5_tts_mabama")
|
19 |
+
model = AutoModelForTextToSpectrogram.from_pretrained("ovieyra21/es_speecht5_tts_mabama")
|
20 |
+
|
21 |
+
|
22 |
try:
|
23 |
+
models, cfg, task = load_model_ensemble_and_task_from_hf_hub("ovieyra21/es_speecht5_tts_mabama")
|
|
|
24 |
if not models:
|
25 |
raise RuntimeError("No se pudo cargar el modelo. Asegúrate de que el nombre del modelo es correcto y que está disponible en Hugging Face Hub.")
|
26 |
model = models[0]
|
|
|
29 |
|
30 |
# Función para generar la salida de texto a voz
|
31 |
def text_to_speech(text):
|
32 |
+
try:
|
33 |
+
# Preprocesamiento del texto
|
34 |
+
tokens = task.source_dictionary.encode_line(text, add_if_not_exist=False)
|
35 |
+
|
36 |
+
# Generar salida de audio
|
37 |
+
with torch.no_grad():
|
38 |
+
sample = {"net_input": {"src_tokens": tokens.unsqueeze(0).long()}}
|
39 |
+
generator = task.build_generator([model], cfg.generation)
|
40 |
+
audio = task.inference_step(generator, [model], sample)
|
41 |
+
|
42 |
+
return audio[0][0].numpy()
|
43 |
+
except Exception as e:
|
44 |
+
return f"Error en la generación de audio: {e}"
|
45 |
|
46 |
# Crear interfaz de Gradio
|
47 |
iface = gr.Interface(
|
48 |
fn=text_to_speech,
|
49 |
inputs=gr.inputs.Textbox(lines=2, placeholder="Ingrese el texto aquí..."),
|
50 |
+
outputs=gr.outputs.Audio(type="numpy", label="Output Audio"),
|
51 |
+
title="Conversor de Texto a Voz",
|
52 |
+
description="Ingrese texto para convertirlo a voz utilizando el modelo speecht5_tts_mabama_es."
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
iface.launch()
|
|