riabayonaor commited on
Commit
9100ef3
1 Parent(s): 59898ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -1,35 +1,31 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
- import scipy.io.wavfile
5
- import numpy as np
6
 
7
- def text_to_speech(text):
8
- # Cargar el modelo y el tokenizador
9
- model_name = "facebook/tts_transformer-es-css10"
10
- processor = AutoTokenizer.from_pretrained(model_name)
11
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
12
 
13
- inputs = processor(text, return_tensors="pt")
14
- with torch.no_grad():
15
- generated_ids = model.generate(inputs.input_ids)
16
-
17
- generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
18
-
19
- # Aquí podrías generar un archivo de audio a partir del texto generado si tuvieras una función para ello
20
- output_path = "/tmp/output.txt"
21
- with open(output_path, "w") as f:
22
- f.write(generated_text)
23
-
24
- return output_path, output_path
 
 
 
 
 
 
 
 
 
25
 
26
- # Crear la interfaz de Gradio
27
- iface = gr.Interface(
28
- fn=text_to_speech,
29
- inputs="text",
30
- outputs=[gr.Textbox(), gr.File()],
31
- title="Spanish Text-to-Speech",
32
- description="Convert text to speech in Spanish using the facebook/tts_transformer-es-css10 model."
33
- )
34
-
35
- iface.launch()
 
1
  import gradio as gr
2
+ from tts import synthesize, TTS_LANGUAGES
3
+ import base64
 
 
4
 
5
+ # Definir la función de síntesis
6
+ def synthesize_audio(text, speed, language):
7
+ return synthesize(text, speed, language)
 
 
8
 
9
+ # Crear la interfaz con Gradio
10
+ with gr.Blocks() as demo:
11
+ gr.Markdown(
12
+ """
13
+ <center>
14
+ <h1>Uso de AI para la generación de audio a partir de texto.</h1>
15
+ <h3>Con este espacio podrás producir audio que lee el texto de entrada. Podrás ajustar la velocidad con la que habla el modelo.</h3>
16
+ </center>
17
+ """
18
+ )
19
+ with gr.Row():
20
+ with gr.Column():
21
+ leng = gr.Radio(choices=["spa","eng"], value="spa", label="Selecciona un idioma entre Inglés (eng) y Español (spa)")
22
+ textbox = gr.Textbox(label="Ingrese texto")
23
+ slider = gr.Slider(minimum=0.1, maximum=4.0, value=1.0, step=0.1, label="Velocidad de voz")
24
+ button = gr.Button("Hablar")
25
+ with gr.Column():
26
+ audio_output = gr.Audio()
27
+ file_output = gr.File(label="Descargar audio")
28
+
29
+ button.click(synthesize_audio, [textbox, slider, leng], [audio_output, file_output])
30
 
31
+ demo.launch()