Spaces:
Runtime error
Runtime error
Commit ·
2a45afb
1
Parent(s): 16cbbc6
App Traductor
Browse files- app.py +31 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
traductor = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-es")
|
| 7 |
+
emitidor_audio = pipeline("text-to-speech", model="suno/bark-smal")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def traducir(frase):
|
| 11 |
+
traduccion = traductor(frase)
|
| 12 |
+
return traduccion[0]["translation_text"]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def emitir_audio(texto_traducido):
|
| 16 |
+
audio = emitir_audio(texto_traducido)
|
| 17 |
+
|
| 18 |
+
audio_array = np.array(audio["audio"][0], dtype=np.float32)
|
| 19 |
+
sampling_rate = audio["sampling_rate"]
|
| 20 |
+
return (sampling_rate,audio_array)
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as aplicacion:
|
| 23 |
+
gr.Markdown("ESTA ES NUESTRA APLICACIÓN")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
entrada = gr.Textbox(placeholder="Frase a traducir", label="Frase")
|
| 26 |
+
traduccion = gr.Textbox(label="Frase en Español")
|
| 27 |
+
salida = gr.Audio(label="Audio en Español")
|
| 28 |
+
|
| 29 |
+
entrada.change(fn=traducir, inputs=entrada, outputs=traduccion)
|
| 30 |
+
btn = gr.Button("Emitir Audio")
|
| 31 |
+
btn.click(fn=emitir_audio, inputs=traduccion, outputs=salida)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers==4.49.0
|
| 3 |
+
torch==2.6.0
|
| 4 |
+
diffusers==0.32.2
|
| 5 |
+
accelerate==1.5.2
|
| 6 |
+
pydantic==2.12.5
|