Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,25 +9,54 @@ summarizers = load_summarizers()
|
|
| 9 |
|
| 10 |
# Función para procesar el archivo cargado
|
| 11 |
def process_file(file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if file is not None:
|
| 13 |
pdf_processor = PDFProcessor()
|
| 14 |
input_text = pdf_processor.pdf_to_text(file.name)
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
return "Por favor, cargue un archivo válido."
|
| 17 |
|
| 18 |
# Función principal para generar resúmenes
|
| 19 |
def summarize(input_text, file, summary_type, method, num_sentences, model_name, max_length, num_beams):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
preprocessor = Preprocessor()
|
| 21 |
|
|
|
|
| 22 |
if file is not None:
|
| 23 |
-
|
| 24 |
-
input_text = pdf_processor.pdf_to_text(file.name)
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
return "Por favor, ingrese texto o cargue un archivo válido."
|
| 28 |
|
| 29 |
cleaned_text = preprocessor.clean_text(input_text)
|
| 30 |
|
|
|
|
| 31 |
if summary_type == "Extractivo":
|
| 32 |
if method == "TF-IDF":
|
| 33 |
summarizer = TFIDFSummarizer()
|
|
|
|
| 9 |
|
| 10 |
# Función para procesar el archivo cargado
|
| 11 |
def process_file(file):
|
| 12 |
+
"""
|
| 13 |
+
Procesa un archivo cargado y extrae texto si es un PDF válido.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
file (UploadedFile): Archivo subido por el usuario.
|
| 17 |
+
|
| 18 |
+
Returns:
|
| 19 |
+
str: Texto extraído del archivo o mensaje de error.
|
| 20 |
+
"""
|
| 21 |
if file is not None:
|
| 22 |
pdf_processor = PDFProcessor()
|
| 23 |
input_text = pdf_processor.pdf_to_text(file.name)
|
| 24 |
+
if input_text.strip():
|
| 25 |
+
return input_text
|
| 26 |
+
return "El archivo no contiene texto procesable."
|
| 27 |
return "Por favor, cargue un archivo válido."
|
| 28 |
|
| 29 |
# Función principal para generar resúmenes
|
| 30 |
def summarize(input_text, file, summary_type, method, num_sentences, model_name, max_length, num_beams):
|
| 31 |
+
"""
|
| 32 |
+
Genera un resumen basado en el texto de entrada o archivo cargado.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
input_text (str): Texto ingresado por el usuario.
|
| 36 |
+
file (UploadedFile): Archivo subido por el usuario.
|
| 37 |
+
summary_type (str): Tipo de resumen: Extractivo, Abstractivo o Combinado.
|
| 38 |
+
method (str): Método de resumen extractivo.
|
| 39 |
+
num_sentences (int): Número de oraciones para el resumen extractivo.
|
| 40 |
+
model_name (str): Nombre del modelo para resumen abstractivo.
|
| 41 |
+
max_length (int): Longitud máxima del resumen generado.
|
| 42 |
+
num_beams (int): Número de haces para búsqueda en el modelo.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
str: Resumen generado o mensaje de error.
|
| 46 |
+
"""
|
| 47 |
preprocessor = Preprocessor()
|
| 48 |
|
| 49 |
+
# Procesar archivo si se sube uno
|
| 50 |
if file is not None:
|
| 51 |
+
input_text = process_file(file)
|
|
|
|
| 52 |
|
| 53 |
+
# Validar que haya texto para resumir
|
| 54 |
+
if not input_text.strip():
|
| 55 |
return "Por favor, ingrese texto o cargue un archivo válido."
|
| 56 |
|
| 57 |
cleaned_text = preprocessor.clean_text(input_text)
|
| 58 |
|
| 59 |
+
# Procesar según el tipo de resumen seleccionado
|
| 60 |
if summary_type == "Extractivo":
|
| 61 |
if method == "TF-IDF":
|
| 62 |
summarizer = TFIDFSummarizer()
|