prueba audio corregida
Browse files- appTraduccion.py +28 -13
appTraduccion.py
CHANGED
|
@@ -1,33 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
-
from PIL import Image
|
| 4 |
-
from diffusers import DiffusionPipeline
|
| 5 |
from transformers import pipeline
|
| 6 |
import numpy as np
|
| 7 |
|
|
|
|
| 8 |
traductor = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-es")
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def traducir(frase):
|
| 12 |
-
traduccion = traductor(frase)
|
| 13 |
return traduccion[0]["translation_text"]
|
| 14 |
|
| 15 |
def emitirAudio(texto_traducido):
|
| 16 |
-
audio = emisorAudio(texto_traducido)
|
| 17 |
|
|
|
|
|
|
|
| 18 |
audio_array = np.array(audio["audio"][0], dtype=np.float32)
|
| 19 |
sampling_rate = audio["sampling_rate"]
|
| 20 |
-
|
| 21 |
return (sampling_rate,audio_array)
|
| 22 |
|
| 23 |
-
with gr.Blocks() as
|
| 24 |
gr.Markdown("ESTA ES NUESTRA APLICACIÓN")
|
| 25 |
with gr.Row():
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
entrada.change(fn=traducir, inputs=entrada, outputs=traduccion)
|
| 31 |
-
btn = gr.Button("Emitir Audio")
|
| 32 |
-
btn.click(fn=emitirAudio, inputs=traduccion, outputs=salida)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
|
| 6 |
traductor = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-es")
|
| 7 |
+
emitidorAudio = pipeline("text-to-speech", model="suno/bark-small")
|
| 8 |
+
callback = gr.CSVLogger()
|
| 9 |
+
|
| 10 |
|
| 11 |
def traducir(frase):
|
| 12 |
+
traduccion = traductor(frase)
|
| 13 |
return traduccion[0]["translation_text"]
|
| 14 |
|
| 15 |
def emitirAudio(texto_traducido):
|
|
|
|
| 16 |
|
| 17 |
+
audio = emitidorAudio(texto_traducido)
|
| 18 |
+
|
| 19 |
audio_array = np.array(audio["audio"][0], dtype=np.float32)
|
| 20 |
sampling_rate = audio["sampling_rate"]
|
| 21 |
+
|
| 22 |
return (sampling_rate,audio_array)
|
| 23 |
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
gr.Markdown("ESTA ES NUESTRA APLICACIÓN")
|
| 26 |
with gr.Row():
|
| 27 |
+
with gr.Column(scale=1):
|
| 28 |
+
entrada = gr.Textbox(placeholder="Frase a traducir", label="Frase")
|
| 29 |
+
with gr.Column(scale=2):
|
| 30 |
+
traduccion = gr.Textbox(label="Frase en Español")
|
| 31 |
+
btn = gr.Button("Emitir Audio")
|
| 32 |
+
with gr.Column(scale=1):
|
| 33 |
+
salida = gr.Audio(label="Audio en Español")
|
| 34 |
+
with gr.Row():
|
| 35 |
+
btnFlag = gr.Button("Flag")
|
| 36 |
|
| 37 |
entrada.change(fn=traducir, inputs=entrada, outputs=traduccion)
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
btn.click(fn=emitirAudio, inputs=traduccion, outputs=salida)
|
| 40 |
+
|
| 41 |
+
# This needs to be called at some point prior to the first call to callback.flag()
|
| 42 |
+
callback.setup([entrada, traduccion, salida], "flagged_data_points")
|
| 43 |
+
|
| 44 |
+
# We can choose which components to flag -- in this case, we'll flag all of them
|
| 45 |
+
btnFlag.click(lambda *args: callback.flag(list(args)), [entrada, traduccion, salida], None, preprocess=False)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
| 48 |
+
|