Update modules/text_analysis/discourse_analysis.py
Browse files
modules/text_analysis/discourse_analysis.py
CHANGED
@@ -91,13 +91,11 @@ ENTITY_LABELS = {
|
|
91 |
|
92 |
#################
|
93 |
|
94 |
-
def fig_to_bytes(fig):
|
95 |
"""Convierte una figura de matplotlib a bytes."""
|
96 |
try:
|
97 |
buf = io.BytesIO()
|
98 |
-
|
99 |
-
fig.savefig(buf, format='png', dpi=100, bbox_inches='tight',
|
100 |
-
compression=9) # M谩xima compresi贸n
|
101 |
buf.seek(0)
|
102 |
return buf.getvalue()
|
103 |
except Exception as e:
|
@@ -220,6 +218,12 @@ def perform_discourse_analysis(text1, text2, nlp, lang):
|
|
220 |
logger.info(f"Figura 1 convertida a {len(graph1_bytes) if graph1_bytes else 0} bytes")
|
221 |
logger.info(f"Figura 2 convertida a {len(graph2_bytes) if graph2_bytes else 0} bytes")
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
# Crear tablas de resultados
|
224 |
table1 = create_concept_table(key_concepts1)
|
225 |
table2 = create_concept_table(key_concepts2)
|
|
|
91 |
|
92 |
#################
|
93 |
|
94 |
+
def fig_to_bytes(fig, dpi=100):
|
95 |
"""Convierte una figura de matplotlib a bytes."""
|
96 |
try:
|
97 |
buf = io.BytesIO()
|
98 |
+
fig.savefig(buf, format='png', dpi=dpi, bbox_inches='tight') # Sin compression
|
|
|
|
|
99 |
buf.seek(0)
|
100 |
return buf.getvalue()
|
101 |
except Exception as e:
|
|
|
218 |
logger.info(f"Figura 1 convertida a {len(graph1_bytes) if graph1_bytes else 0} bytes")
|
219 |
logger.info(f"Figura 2 convertida a {len(graph2_bytes) if graph2_bytes else 0} bytes")
|
220 |
|
221 |
+
# Verificar que las conversiones fueron exitosas antes de continuar
|
222 |
+
if not graph1_bytes or not graph2_bytes:
|
223 |
+
logger.error("Error al convertir figuras a bytes - obteniendo 0 bytes")
|
224 |
+
# Opci贸n 1: Devolver error
|
225 |
+
raise ValueError("No se pudieron convertir las figuras a bytes")
|
226 |
+
|
227 |
# Crear tablas de resultados
|
228 |
table1 = create_concept_table(key_concepts1)
|
229 |
table2 = create_concept_table(key_concepts2)
|