From 5862a69ac22c013bddb54a68809b61a01c2c1de9 Mon Sep 17 00:00:00 2001
From: sergio
Date: Tue, 16 Dec 2025 00:00:58 +0100
Subject: [PATCH] test
---
README.md | 53 ++++++++++++++++++++++----
apply_content.py | 24 ++++++++++++
claude.md | 44 +++++++++++++++++++--
thesis_output/plantilla_individual.htm | 26 +------------
4 files changed, 112 insertions(+), 35 deletions(-)
diff --git a/README.md b/README.md
index 093c835..3de47c8 100644
--- a/README.md
+++ b/README.md
@@ -70,8 +70,8 @@ PDF (académico UNIR)
```
MastersThesis/
-├── docs/ # Capítulos del TFM (estructura UNIR)
-│ ├── 00_resumen.md # Resumen + Abstract
+├── docs/ # Capítulos del TFM en Markdown (estructura UNIR)
+│ ├── 00_resumen.md # Resumen + Abstract + Keywords
│ ├── 01_introduccion.md # Cap. 1: Introducción (1.1-1.3)
│ ├── 02_contexto_estado_arte.md # Cap. 2: Contexto y estado del arte (2.1-2.3)
│ ├── 03_objetivos_metodologia.md # Cap. 3: Objetivos y metodología (3.1-3.4)
@@ -79,6 +79,11 @@ MastersThesis/
│ ├── 05_conclusiones_trabajo_futuro.md # Cap. 5: Conclusiones (5.1-5.2)
│ ├── 06_referencias_bibliograficas.md # Referencias bibliográficas (APA)
│ └── 07_anexo_a.md # Anexo A: Código fuente y datos
+├── thesis_output/ # Documento final generado
+│ ├── plantilla_individual.htm # TFM completo (abrir en Word)
+│ └── figures/ # Figuras generadas desde Mermaid
+│ ├── figura_1.png ... figura_7.png
+│ └── figures_manifest.json
├── src/
│ ├── paddle_ocr_fine_tune_unir_raytune.ipynb # Experimento principal
│ ├── paddle_ocr_tuning.py # Script de evaluación CLI
@@ -90,6 +95,8 @@ MastersThesis/
│ ├── instrucciones.pdf
│ ├── plantilla_individual.pdf
│ └── plantilla_individual.htm
+├── apply_content.py # Genera documento TFM desde docs/ + plantilla
+├── generate_mermaid_figures.py # Convierte diagramas Mermaid a PNG
├── ocr_benchmark_notebook.ipynb # Benchmark comparativo inicial
└── README.md
```
@@ -154,6 +161,32 @@ python src/paddle_ocr_tuning.py \
---
+## Generación del Documento TFM
+
+### Generar documento Word desde Markdown
+
+```bash
+# 1. Generar figuras desde diagramas Mermaid
+python3 generate_mermaid_figures.py
+
+# 2. Aplicar contenido de docs/ a la plantilla UNIR
+python3 apply_content.py
+
+# 3. Abrir en Word y actualizar índices
+# - Abrir thesis_output/plantilla_individual.htm en Microsoft Word
+# - Presionar Ctrl+A luego F9 para actualizar todos los índices
+# - Guardar como .docx
+```
+
+**Contenido generado automáticamente:**
+- 30 tablas con formato `Piedefoto-tabla` (Tabla X. *Título* + Fuente)
+- 7 figuras desde Mermaid con formato `Piedefoto-tabla` (Figura X. *Título* + Fuente)
+- 25 referencias en formato APA con sangría francesa
+- Resumen y Abstract con palabras clave reales
+- Eliminación automática de textos de instrucción de la plantilla
+
+---
+
## Trabajo Pendiente para Completar el TFM
### Contexto: Limitaciones de Hardware
@@ -165,6 +198,13 @@ Este trabajo adoptó la estrategia de **optimización de hiperparámetros** en l
La optimización de hiperparámetros demostró ser una **alternativa efectiva** al fine-tuning, logrando una reducción del 80.9% en el CER sin reentrenar el modelo.
+### Tareas Completadas
+
+- [x] **Estructura docs/ según plantilla UNIR**: Todos los capítulos siguen numeración exacta (1.1, 1.2, etc.)
+- [x] **Añadir diagramas Mermaid**: 7 diagramas añadidos (pipeline OCR, arquitectura Ray Tune, gráficos de comparación)
+- [x] **Generar documento TFM unificado**: Script `apply_content.py` genera documento completo desde docs/
+- [x] **Convertir Mermaid a PNG**: Script `generate_mermaid_figures.py` genera figuras automáticamente
+
### Tareas Pendientes
#### 1. Validación del Enfoque (Prioridad Alta)
@@ -178,9 +218,8 @@ La optimización de hiperparámetros demostró ser una **alternativa efectiva**
- [ ] **Evaluación con GPU**: Medir tiempos de inferencia con aceleración GPU para escenarios de producción
#### 3. Documentación y Presentación (Prioridad Alta)
-- [ ] **Completar memoria TFM**: Unificar los capítulos del directorio `docs/` en documento final siguiendo plantilla UNIR
- [ ] **Crear presentación**: Preparar slides para la defensa del TFM
-- [x] **Añadir diagramas y figuras**: ~~Incluir visualizaciones de los resultados de Ray Tune~~ (completado: 4 diagramas Mermaid añadidos)
+- [ ] **Revisión final del documento**: Verificar formato, índices y contenido en Word
#### 4. Extensiones Futuras (Opcional)
- [ ] **Herramienta de configuración automática**: Desarrollar una herramienta que determine automáticamente la configuración óptima para un nuevo tipo de documento
@@ -189,9 +228,9 @@ La optimización de hiperparámetros demostró ser una **alternativa efectiva**
### Recomendación de Próximos Pasos
-1. **Inmediato**: Validar en 2-3 tipos de documentos adicionales para demostrar generalización
-2. **Corto plazo**: Ampliar dataset y revisar ground truth manualmente
-3. **Para la defensa**: Completar memoria unificada y crear presentación con visualizaciones
+1. **Inmediato**: Abrir documento generado en Word, actualizar índices (Ctrl+A, F9), guardar como .docx
+2. **Corto plazo**: Validar en 2-3 tipos de documentos adicionales para demostrar generalización
+3. **Para la defensa**: Crear presentación con visualizaciones de resultados
---
diff --git a/apply_content.py b/apply_content.py
index b5d332e..285d29f 100644
--- a/apply_content.py
+++ b/apply_content.py
@@ -456,6 +456,30 @@ def main():
# Clear old figure/table index entries (they need to be regenerated in Word)
print("Clearing old index entries...")
+
+ # Remove ALL content from MsoTof paragraphs that reference template examples
+ # The indices will be regenerated when user opens in Word and presses Ctrl+A, F9
+ for p in soup.find_all('p', class_='MsoTof'):
+ text = p.get_text()
+ # Check for figure index entries with template examples
+ if 'Figura' in text and 'Ejemplo' in text:
+ # Remove all tags (the actual index entry links)
+ for a in p.find_all('a'):
+ a.decompose()
+ # Also remove any remaining text content that shows the example
+ for span in p.find_all('span', style=lambda x: x and 'mso-no-proof' in str(x)):
+ if 'Ejemplo' in span.get_text():
+ span.decompose()
+ print(" ✓ Cleared figure index example entry")
+ # Check for table index entries with template examples
+ if 'Tabla' in text and 'Ejemplo' in text:
+ for a in p.find_all('a'):
+ a.decompose()
+ for span in p.find_all('span', style=lambda x: x and 'mso-no-proof' in str(x)):
+ if 'Ejemplo' in span.get_text():
+ span.decompose()
+ print(" ✓ Cleared table index example entry")
+
# Remove old figure index entries that reference template examples
for p in soup.find_all('p', class_='MsoToc3'):
text = p.get_text()
diff --git a/claude.md b/claude.md
index 1f8671d..4d92827 100644
--- a/claude.md
+++ b/claude.md
@@ -59,6 +59,11 @@ MastersThesis/
│ ├── 05_conclusiones_trabajo_futuro.md # 5. Conclusiones (5.1, 5.2)
│ ├── 06_referencias_bibliograficas.md # Referencias bibliográficas (APA format)
│ └── 07_anexo_a.md # Anexo A: Código fuente y datos
+├── thesis_output/ # Generated thesis document
+│ ├── plantilla_individual.htm # Complete TFM (open in Word)
+│ └── figures/ # PNG figures from Mermaid diagrams
+│ ├── figura_1.png ... figura_7.png
+│ └── figures_manifest.json
├── src/
│ ├── paddle_ocr_fine_tune_unir_raytune.ipynb # Main experiment (64 trials)
│ ├── paddle_ocr_tuning.py # CLI evaluation script
@@ -69,7 +74,9 @@ MastersThesis/
├── instructions/ # UNIR instructions and template
│ ├── instrucciones.pdf # TFE writing guidelines
│ ├── plantilla_individual.pdf # Word template (PDF version)
-│ └── plantilla_individual.htm # Word template (HTML version, readable)
+│ └── plantilla_individual.htm # Word template (HTML version, source)
+├── apply_content.py # Generates TFM document from docs/ + template
+├── generate_mermaid_figures.py # Converts Mermaid diagrams to PNG
├── ocr_benchmark_notebook.ipynb # Initial OCR benchmark
└── README.md
```
@@ -115,19 +122,48 @@ The template (`plantilla_individual.pdf`) requires **5 chapters**. The docs/ fil
### Completed Tasks
- [x] **Structure docs/ to match UNIR template** - All chapters now follow exact numbering (1.1, 1.2, etc.)
-- [x] **Add Mermaid diagrams** - 4 diagrams added (OCR pipeline, Ray Tune architecture, CER comparison charts)
+- [x] **Add Mermaid diagrams** - 7 diagrams added (OCR pipeline, Ray Tune architecture, methodology flowcharts, CER comparison charts)
+- [x] **Generate unified thesis document** - `apply_content.py` generates complete document from docs/
+- [x] **Convert Mermaid to PNG** - `generate_mermaid_figures.py` generates figures automatically
+- [x] **Proper template formatting** - Tables/figures use `Piedefoto-tabla` class, references use `MsoBibliography`
### Priority Tasks
1. **Validate on other document types** - Test optimal config on invoices, forms, contracts
2. **Expand dataset** - Current dataset has only 24 pages
-3. **Complete unified thesis document** - Merge docs/ chapters into final UNIR Word format
-4. **Create presentation slides** - For thesis defense
+3. **Create presentation slides** - For thesis defense
+4. **Final document review** - Open in Word, update indices (Ctrl+A, F9), verify formatting
### Optional Extensions
- Explore `text_det_unclip_ratio` parameter (was fixed at 0.0)
- Compare with actual fine-tuning (if GPU access obtained)
- Multi-objective optimization (CER + WER + inference time)
+## Thesis Document Generation
+
+To regenerate the thesis document:
+
+```bash
+# 1. Generate PNG figures from Mermaid diagrams
+python3 generate_mermaid_figures.py
+
+# 2. Apply docs/ content to UNIR template
+python3 apply_content.py
+
+# 3. Open in Word and finalize
+# - Open thesis_output/plantilla_individual.htm in Microsoft Word
+# - Press Ctrl+A then F9 to update all indices
+# - Save as .docx
+```
+
+**What `apply_content.py` does:**
+- Replaces Resumen and Abstract with actual content + keywords
+- Replaces all 5 chapters with content from docs/
+- Replaces Referencias with APA-formatted bibliography
+- Replaces Anexo with repository information
+- Converts Mermaid diagrams to embedded PNG images
+- Formats tables with `Piedefoto-tabla` captions and sources
+- Removes template instruction text ("Importante:", "Ejemplo de nota al pie", etc.)
+
---
## UNIR TFE Document Guidelines
diff --git a/thesis_output/plantilla_individual.htm b/thesis_output/plantilla_individual.htm
index cdf2b41..2085cf0 100644
--- a/thesis_output/plantilla_individual.htm
+++ b/thesis_output/plantilla_individual.htm
@@ -4496,18 +4496,7 @@ mso-ascii-theme-font:minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-
lang=ES style='mso-bidi-font-family:Arial;background:yellow;mso-highlight:yellow'> TOC \f c \h \z \t "Título
-9;1;Figuras;1" \c "Figura" Figura 1. Ejemplo
-de figura realizada para nuestro trabajo. 2
Tabla 1. Ejemplo
-de tabla con sus principales elementos. 2