Spaces:
Sleeping
Sleeping
Primera versión.
Browse filesCrear el traductor desde 0.
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Cargar el modelo de traducción
|
| 5 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
| 6 |
+
|
| 7 |
+
# Función para traducir texto
|
| 8 |
+
def translate_text(text):
|
| 9 |
+
translation = translator(text)
|
| 10 |
+
return translation[0]['translation_text']
|
| 11 |
+
|
| 12 |
+
# Crear la interfaz con Gradio
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=translate_text,
|
| 15 |
+
inputs=gr.Textbox(label="Texto en inglés"),
|
| 16 |
+
outputs=gr.Textbox(label="Traducción en español"),
|
| 17 |
+
title="Traductor Inglés - Español",
|
| 18 |
+
description="Introduce un texto en inglés y obtén la traducción al español.",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Ejecutar la aplicación
|
| 22 |
+
iface.launch()
|