Spaces:
Running
Running
Update modules/discourse/discourse_interface.py
Browse files
modules/discourse/discourse_interface.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
import logging
|
| 7 |
from ..utils.widget_utils import generate_unique_key
|
|
@@ -11,6 +12,7 @@ from ..database.discourse_mongo_db import store_student_discourse_result
|
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
|
|
|
| 14 |
def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
| 15 |
"""
|
| 16 |
Interfaz para el análisis del discurso
|
|
@@ -29,7 +31,7 @@ def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
|
| 29 |
}
|
| 30 |
|
| 31 |
# 2. Título y descripción
|
| 32 |
-
#st.subheader(discourse_t.get('discourse_title', 'Análisis del Discurso'))
|
| 33 |
st.info(discourse_t.get('initial_instruction',
|
| 34 |
'Cargue dos archivos de texto para realizar un análisis comparativo del discurso.'))
|
| 35 |
|
|
@@ -128,7 +130,6 @@ def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
|
| 128 |
|
| 129 |
|
| 130 |
#####################################################################################################################
|
| 131 |
-
|
| 132 |
def display_discourse_results(result, lang_code, discourse_t):
|
| 133 |
"""
|
| 134 |
Muestra los resultados del análisis del discurso
|
|
@@ -198,9 +199,27 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 198 |
"""
|
| 199 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 200 |
|
|
|
|
| 201 |
if 'graph1' in result:
|
| 202 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
# Botones y controles
|
| 206 |
button_col1, spacer_col1 = st.columns([1,4])
|
|
@@ -245,9 +264,27 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 245 |
"""
|
| 246 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 247 |
|
| 248 |
-
|
|
|
|
| 249 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
# Botones y controles
|
| 253 |
button_col2, spacer_col2 = st.columns([1,4])
|
|
@@ -278,4 +315,4 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 278 |
|
| 279 |
# Nota informativa sobre la comparación
|
| 280 |
st.info(discourse_t.get('comparison_note',
|
| 281 |
-
'La funcionalidad de comparación detallada estará disponible en una próxima actualización.'))
|
|
|
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
import logging
|
| 8 |
from ..utils.widget_utils import generate_unique_key
|
|
|
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
#############################################################################################
|
| 16 |
def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
| 17 |
"""
|
| 18 |
Interfaz para el análisis del discurso
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
# 2. Título y descripción
|
| 34 |
+
# st.subheader(discourse_t.get('discourse_title', 'Análisis del Discurso'))
|
| 35 |
st.info(discourse_t.get('initial_instruction',
|
| 36 |
'Cargue dos archivos de texto para realizar un análisis comparativo del discurso.'))
|
| 37 |
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
#####################################################################################################################
|
|
|
|
| 133 |
def display_discourse_results(result, lang_code, discourse_t):
|
| 134 |
"""
|
| 135 |
Muestra los resultados del análisis del discurso
|
|
|
|
| 199 |
"""
|
| 200 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 201 |
|
| 202 |
+
# Verificar el tipo de graph1 de manera más robusta
|
| 203 |
if 'graph1' in result:
|
| 204 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 205 |
+
|
| 206 |
+
# Más información para depuración
|
| 207 |
+
graph_type = type(result['graph1']).__name__
|
| 208 |
+
graph_size = len(result['graph1']) if isinstance(result['graph1'], bytes) else "N/A"
|
| 209 |
+
logger.info(f"Tipo de graph1: {graph_type}, Tamaño: {graph_size}")
|
| 210 |
+
|
| 211 |
+
if isinstance(result['graph1'], bytes) and len(result['graph1']) > 0:
|
| 212 |
+
# Es bytes válidos
|
| 213 |
+
st.image(result['graph1'])
|
| 214 |
+
elif isinstance(result['graph1'], plt.Figure):
|
| 215 |
+
# Es una figura de matplotlib
|
| 216 |
+
st.pyplot(result['graph1'])
|
| 217 |
+
elif result['graph1'] is None:
|
| 218 |
+
# Es None
|
| 219 |
+
st.warning("Gráfico no disponible")
|
| 220 |
+
else:
|
| 221 |
+
# Otro tipo o bytes vacíos
|
| 222 |
+
st.warning(f"Formato de gráfico no reconocido: {graph_type}")
|
| 223 |
|
| 224 |
# Botones y controles
|
| 225 |
button_col1, spacer_col1 = st.columns([1,4])
|
|
|
|
| 264 |
"""
|
| 265 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 266 |
|
| 267 |
+
# Verificar el tipo de graph1 de manera más robusta
|
| 268 |
+
if 'graph1' in result:
|
| 269 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 270 |
+
|
| 271 |
+
# Más información para depuración
|
| 272 |
+
graph_type = type(result['graph2']).__name__
|
| 273 |
+
graph_size = len(result['graph2']) if isinstance(result['graph2'], bytes) else "N/A"
|
| 274 |
+
logger.info(f"Tipo de graph2: {graph_type}, Tamaño: {graph_size}")
|
| 275 |
+
|
| 276 |
+
if isinstance(result['graph2'], bytes) and len(result['graph2']) > 0:
|
| 277 |
+
# Es bytes válidos
|
| 278 |
+
st.image(result['graph2'])
|
| 279 |
+
elif isinstance(result['graph2'], plt.Figure):
|
| 280 |
+
# Es una figura de matplotlib
|
| 281 |
+
st.pyplot(result['graph2'])
|
| 282 |
+
elif result['graph2'] is None:
|
| 283 |
+
# Es None
|
| 284 |
+
st.warning("Gráfico no disponible")
|
| 285 |
+
else:
|
| 286 |
+
# Otro tipo o bytes vacíos
|
| 287 |
+
st.warning(f"Formato de gráfico no reconocido: {graph_type}")
|
| 288 |
|
| 289 |
# Botones y controles
|
| 290 |
button_col2, spacer_col2 = st.columns([1,4])
|
|
|
|
| 315 |
|
| 316 |
# Nota informativa sobre la comparación
|
| 317 |
st.info(discourse_t.get('comparison_note',
|
| 318 |
+
'La funcionalidad de comparación detallada estará disponible en una próxima actualización.'))
|