ovieyra21 commited on
Commit
05b40ca
verified
1 Parent(s): 27ad2ce

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
4
+
5
+ # Cargar el modelo
6
+ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
7
+ "gitgato/speecht5_tts_mabama_es"
8
+ )
9
+ model = models[0]
10
+
11
+ # Funci贸n para generar la salida de texto a voz
12
+ def text_to_speech(text):
13
+ # Preprocesamiento del texto
14
+ tokens = task.source_dictionary.encode_line(text, add_if_not_exist=False)
15
+
16
+ # Generar salida de audio
17
+ with torch.no_grad():
18
+ sample = {"net_input": {"src_tokens": tokens.unsqueeze(0).long()}}
19
+ generator = task.build_generator([model], cfg.generation)
20
+ audio = task.inference_step(generator, [model], sample)
21
+
22
+ return audio[0][0].numpy()
23
+
24
+ # Crear interfaz de Gradio
25
+ iface = gr.Interface(
26
+ fn=text_to_speech,
27
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Ingrese el texto aqu铆..."),
28
+ outputs=gr.outputs.Audio(type="numpy", label="Output Audio")
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()