Update app.py
Browse files
app.py
CHANGED
|
@@ -18,26 +18,35 @@ def extract_names_from_text(text):
|
|
| 18 |
return persons
|
| 19 |
|
| 20 |
# Función para dividir el texto en fragmentos más pequeños
|
| 21 |
-
def split_text(
|
| 22 |
-
paragraphs = text.split('\n\n') # Divide el texto en párrafos
|
| 23 |
result = []
|
| 24 |
current_chunk = []
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
current_chunk = [paragraph]
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
if current_chunk:
|
| 37 |
-
result.append('
|
| 38 |
|
| 39 |
return result
|
| 40 |
|
|
|
|
| 41 |
# Función principal para extraer nombres de personas desde un archivo DOCX
|
| 42 |
def extract_names_from_docx(docx_file):
|
| 43 |
# Cargar el archivo DOCX
|
|
|
|
| 18 |
return persons
|
| 19 |
|
| 20 |
# Función para dividir el texto en fragmentos más pequeños
|
| 21 |
+
def split_text(file_path, max_length=100000):
|
|
|
|
| 22 |
result = []
|
| 23 |
current_chunk = []
|
| 24 |
+
current_length = 0
|
| 25 |
|
| 26 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 27 |
+
for line in file:
|
| 28 |
+
if line.strip() == '':
|
| 29 |
+
# Maneja el separador de párrafos
|
| 30 |
+
paragraph_length = 2 # '\n\n'
|
| 31 |
+
else:
|
| 32 |
+
paragraph_length = len(line)
|
|
|
|
| 33 |
|
| 34 |
+
if current_length + paragraph_length <= max_length:
|
| 35 |
+
current_chunk.append(line)
|
| 36 |
+
current_length += paragraph_length
|
| 37 |
+
else:
|
| 38 |
+
# Almacena el chunk actual
|
| 39 |
+
result.append(''.join(current_chunk))
|
| 40 |
+
current_chunk = [line]
|
| 41 |
+
current_length = paragraph_length
|
| 42 |
+
|
| 43 |
+
# Añade el último fragmento
|
| 44 |
if current_chunk:
|
| 45 |
+
result.append(''.join(current_chunk))
|
| 46 |
|
| 47 |
return result
|
| 48 |
|
| 49 |
+
|
| 50 |
# Función principal para extraer nombres de personas desde un archivo DOCX
|
| 51 |
def extract_names_from_docx(docx_file):
|
| 52 |
# Cargar el archivo DOCX
|