Spaces:
Runtime error
Runtime error
Add application file
Browse files- app.py +44 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
| 3 |
+
|
| 4 |
+
# Cargar el modelo y el tokenizador
|
| 5 |
+
model = MBartForConditionalGeneration.from_pretrained("eslamxm/MBART-finetuned-Spanish")
|
| 6 |
+
tokenizer = MBart50TokenizerFast.from_pretrained("eslamxm/MBART-finetuned-Spanish")
|
| 7 |
+
|
| 8 |
+
# Función para generar el resumen
|
| 9 |
+
def resumir_texto(texto):
|
| 10 |
+
inputs = tokenizer(texto, return_tensors="pt", max_length=1024, truncation=True)
|
| 11 |
+
resumen_ids = model.generate(
|
| 12 |
+
inputs["input_ids"],
|
| 13 |
+
max_length=150,
|
| 14 |
+
min_length=40,
|
| 15 |
+
length_penalty=2.0,
|
| 16 |
+
num_beams=4,
|
| 17 |
+
early_stopping=True
|
| 18 |
+
)
|
| 19 |
+
resumen = tokenizer.decode(resumen_ids[0], skip_special_tokens=True)
|
| 20 |
+
return resumen
|
| 21 |
+
|
| 22 |
+
# Crear la interfaz con Gradio
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("## 📝 Resumen de Textos en Español")
|
| 25 |
+
gr.Markdown("Introduce un texto en español y obtén un resumen generado por el modelo MBART.")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
with gr.Column():
|
| 29 |
+
entrada = gr.Textbox(
|
| 30 |
+
label="Texto de entrada",
|
| 31 |
+
placeholder="Escribe o pega aquí el texto que deseas resumir...",
|
| 32 |
+
lines=10
|
| 33 |
+
)
|
| 34 |
+
boton = gr.Button("Generar Resumen")
|
| 35 |
+
with gr.Column():
|
| 36 |
+
salida = gr.Textbox(
|
| 37 |
+
label="Resumen generado",
|
| 38 |
+
placeholder="El resumen aparecerá aquí...",
|
| 39 |
+
lines=10
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
boton.click(fn=resumir_texto, inputs=entrada, outputs=salida)
|
| 43 |
+
|
| 44 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers==4.20.0
|
| 2 |
+
torch==1.11.0
|
| 3 |
+
datasets==2.3.2
|
| 4 |
+
tokenizers==0.12.1
|