Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
|
|
|
|
|
|
4 |
def traductor(text):
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
8 |
demo = gr.Interface(traductor, inputs="text", outputs="text")
|
9 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Crear el pipeline una vez al inicio para evitar cargas repetitivas
|
5 |
+
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en")
|
6 |
+
|
7 |
def traductor(text):
|
8 |
+
try:
|
9 |
+
# Realizar la traducci贸n usando el pipeline precargado
|
10 |
+
result = pipe(text)
|
11 |
+
return result[0]['translation_text']
|
12 |
+
except Exception as e:
|
13 |
+
# Devolver un mensaje de error en caso de que algo falle
|
14 |
+
return f"Error: {str(e)}"
|
15 |
|
16 |
+
# Configuraci贸n de la interfaz de Gradio
|
17 |
demo = gr.Interface(traductor, inputs="text", outputs="text")
|
18 |
demo.launch()
|