Spaces:
Sleeping
Sleeping
Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
|
@@ -151,135 +151,163 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
| 151 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
| 152 |
st.error("Ocurrió un error al cargar la interfaz")
|
| 153 |
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
"""
|
| 156 |
Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
|
| 157 |
"""
|
| 158 |
try:
|
| 159 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
metrics_col, graph_col = st.columns([1, 1.5])
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
metrics_config = [
|
| 164 |
-
{
|
| 165 |
-
'label': "Vocabulario",
|
| 166 |
-
'key': 'vocabulary',
|
| 167 |
-
'value': metrics['vocabulary']['normalized_score'],
|
| 168 |
-
'help': "Riqueza y variedad del vocabulario",
|
| 169 |
-
'thresholds': {'min': 0.60, 'target': 0.75}
|
| 170 |
-
},
|
| 171 |
-
{
|
| 172 |
-
'label': "Estructura",
|
| 173 |
-
'key': 'structure',
|
| 174 |
-
'value': metrics['structure']['normalized_score'],
|
| 175 |
-
'help': "Organización y complejidad de oraciones",
|
| 176 |
-
'thresholds': {'min': 0.65, 'target': 0.80}
|
| 177 |
-
},
|
| 178 |
-
{
|
| 179 |
-
'label': "Cohesión",
|
| 180 |
-
'key': 'cohesion',
|
| 181 |
-
'value': metrics['cohesion']['normalized_score'],
|
| 182 |
-
'help': "Conexión y fluidez entre ideas",
|
| 183 |
-
'thresholds': {'min': 0.55, 'target': 0.70}
|
| 184 |
-
},
|
| 185 |
-
{
|
| 186 |
-
'label': "Claridad",
|
| 187 |
-
'key': 'clarity',
|
| 188 |
-
'value': metrics['clarity']['normalized_score'],
|
| 189 |
-
'help': "Facilidad de comprensión del texto",
|
| 190 |
-
'thresholds': {'min': 0.60, 'target': 0.75}
|
| 191 |
-
}
|
| 192 |
-
]
|
| 193 |
-
|
| 194 |
-
# Mostrar métricas verticalmente
|
| 195 |
with metrics_col:
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
for metric in metrics_config:
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
)
|
| 229 |
-
st.markdown("<div style='margin-bottom: 1rem;'></div>", unsafe_allow_html=True)
|
| 230 |
|
| 231 |
# Gráfico radar en la columna derecha
|
| 232 |
with graph_col:
|
| 233 |
-
|
| 234 |
-
categories = [m['label'] for m in metrics_config]
|
| 235 |
-
values_user = [m['value'] for m in metrics_config]
|
| 236 |
-
min_values = [m['thresholds']['min'] for m in metrics_config]
|
| 237 |
-
target_values = [m['thresholds']['target'] for m in metrics_config]
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
|
| 243 |
-
# Configurar radar
|
| 244 |
-
angles = [n / float(len(categories)) * 2 * np.pi for n in range(len(categories))]
|
| 245 |
-
angles += angles[:1]
|
| 246 |
-
values_user += values_user[:1]
|
| 247 |
-
min_values += min_values[:1]
|
| 248 |
-
target_values += target_values[:1]
|
| 249 |
|
| 250 |
-
# Configurar ejes
|
| 251 |
-
ax.set_xticks(angles[:-1])
|
| 252 |
-
ax.set_xticklabels(categories, fontsize=10)
|
| 253 |
-
circle_ticks = np.arange(0, 1.1, 0.2)
|
| 254 |
-
ax.set_yticks(circle_ticks)
|
| 255 |
-
ax.set_yticklabels([f'{tick:.1f}' for tick in circle_ticks], fontsize=8)
|
| 256 |
-
ax.set_ylim(0, 1)
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
except Exception as e:
|
| 284 |
-
logger.error(f"Error mostrando
|
| 285 |
-
st.error("Error al mostrar
|
|
|
|
|
|
| 151 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
| 152 |
st.error("Ocurrió un error al cargar la interfaz")
|
| 153 |
|
| 154 |
+
###################################3333
|
| 155 |
+
|
| 156 |
+
display_results(st.session_state.current_metrics, text_type='student_essay') # o el tipo por defecto que prefieras
|
| 157 |
"""
|
| 158 |
Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
|
| 159 |
"""
|
| 160 |
try:
|
| 161 |
+
# Obtener umbrales según el tipo de texto seleccionado
|
| 162 |
+
thresholds = TEXT_TYPES[text_type]['thresholds'] if text_type else {
|
| 163 |
+
'vocabulary': {'min': 0.60, 'target': 0.75},
|
| 164 |
+
'structure': {'min': 0.65, 'target': 0.80},
|
| 165 |
+
'cohesion': {'min': 0.55, 'target': 0.70},
|
| 166 |
+
'clarity': {'min': 0.60, 'target': 0.75}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
# Crear dos columnas para las métricas y el gráfico
|
| 170 |
metrics_col, graph_col = st.columns([1, 1.5])
|
| 171 |
|
| 172 |
+
# Columna de métricas y radio buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
with metrics_col:
|
| 174 |
+
# Radio buttons para tipo de texto
|
| 175 |
+
st.markdown("### Tipo de texto")
|
| 176 |
+
selected_type = st.radio(
|
| 177 |
+
"",
|
| 178 |
+
options=list(TEXT_TYPES.keys()),
|
| 179 |
+
format_func=lambda x: TEXT_TYPES[x]['name'],
|
| 180 |
+
key="text_type_radio",
|
| 181 |
+
help="Selecciona el tipo de texto para ajustar los criterios de evaluación"
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# Actualizar umbrales si cambia el tipo
|
| 185 |
+
if selected_type != text_type:
|
| 186 |
+
thresholds = TEXT_TYPES[selected_type]['thresholds']
|
| 187 |
|
| 188 |
+
st.markdown("<div style='margin-bottom: 1.5rem;'></div>", unsafe_allow_html=True)
|
| 189 |
+
|
| 190 |
+
# Configuración de métricas
|
| 191 |
+
metrics_config = [
|
| 192 |
+
{
|
| 193 |
+
'label': "Vocabulario",
|
| 194 |
+
'key': 'vocabulary',
|
| 195 |
+
'value': metrics['vocabulary']['normalized_score'],
|
| 196 |
+
'help': "Riqueza y variedad del vocabulario",
|
| 197 |
+
'thresholds': thresholds['vocabulary']
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
'label': "Estructura",
|
| 201 |
+
'key': 'structure',
|
| 202 |
+
'value': metrics['structure']['normalized_score'],
|
| 203 |
+
'help': "Organización y complejidad de oraciones",
|
| 204 |
+
'thresholds': thresholds['structure']
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
'label': "Cohesión",
|
| 208 |
+
'key': 'cohesion',
|
| 209 |
+
'value': metrics['cohesion']['normalized_score'],
|
| 210 |
+
'help': "Conexión y fluidez entre ideas",
|
| 211 |
+
'thresholds': thresholds['cohesion']
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
'label': "Claridad",
|
| 215 |
+
'key': 'clarity',
|
| 216 |
+
'value': metrics['clarity']['normalized_score'],
|
| 217 |
+
'help': "Facilidad de comprensión del texto",
|
| 218 |
+
'thresholds': thresholds['clarity']
|
| 219 |
+
}
|
| 220 |
+
]
|
| 221 |
+
|
| 222 |
+
# Mostrar métricas
|
| 223 |
for metric in metrics_config:
|
| 224 |
+
value = metric['value']
|
| 225 |
+
if value < metric['thresholds']['min']:
|
| 226 |
+
status = "⚠️ Por mejorar"
|
| 227 |
+
color = "inverse"
|
| 228 |
+
elif value < metric['thresholds']['target']:
|
| 229 |
+
status = "📈 Aceptable"
|
| 230 |
+
color = "off"
|
| 231 |
+
else:
|
| 232 |
+
status = "✅ Óptimo"
|
| 233 |
+
color = "normal"
|
| 234 |
+
|
| 235 |
+
st.metric(
|
| 236 |
+
metric['label'],
|
| 237 |
+
f"{value:.2f}",
|
| 238 |
+
f"{status} (Meta: {metric['thresholds']['target']:.2f})",
|
| 239 |
+
delta_color=color,
|
| 240 |
+
help=metric['help']
|
| 241 |
+
)
|
| 242 |
+
st.markdown("<div style='margin-bottom: 0.5rem;'></div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
| 243 |
|
| 244 |
# Gráfico radar en la columna derecha
|
| 245 |
with graph_col:
|
| 246 |
+
display_radar_chart(metrics_config, thresholds)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
+
except Exception as e:
|
| 249 |
+
logger.error(f"Error mostrando resultados: {str(e)}")
|
| 250 |
+
st.error("Error al mostrar los resultados")
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
+
######################################
|
| 255 |
+
def display_radar_chart(metrics_config, thresholds):
|
| 256 |
+
"""
|
| 257 |
+
Muestra el gráfico radar con los resultados.
|
| 258 |
+
"""
|
| 259 |
+
try:
|
| 260 |
+
# Preparar datos para el gráfico
|
| 261 |
+
categories = [m['label'] for m in metrics_config]
|
| 262 |
+
values_user = [m['value'] for m in metrics_config]
|
| 263 |
+
min_values = [m['thresholds']['min'] for m in metrics_config]
|
| 264 |
+
target_values = [m['thresholds']['target'] for m in metrics_config]
|
| 265 |
|
| 266 |
+
# Crear y configurar gráfico
|
| 267 |
+
fig = plt.figure(figsize=(8, 8))
|
| 268 |
+
ax = fig.add_subplot(111, projection='polar')
|
| 269 |
|
| 270 |
+
# Configurar radar
|
| 271 |
+
angles = [n / float(len(categories)) * 2 * np.pi for n in range(len(categories))]
|
| 272 |
+
angles += angles[:1]
|
| 273 |
+
values_user += values_user[:1]
|
| 274 |
+
min_values += min_values[:1]
|
| 275 |
+
target_values += target_values[:1]
|
| 276 |
+
|
| 277 |
+
# Configurar ejes
|
| 278 |
+
ax.set_xticks(angles[:-1])
|
| 279 |
+
ax.set_xticklabels(categories, fontsize=10)
|
| 280 |
+
circle_ticks = np.arange(0, 1.1, 0.2)
|
| 281 |
+
ax.set_yticks(circle_ticks)
|
| 282 |
+
ax.set_yticklabels([f'{tick:.1f}' for tick in circle_ticks], fontsize=8)
|
| 283 |
+
ax.set_ylim(0, 1)
|
| 284 |
+
|
| 285 |
+
# Dibujar áreas de umbrales
|
| 286 |
+
ax.plot(angles, min_values, '#e74c3c', linestyle='--', linewidth=1, label='Mínimo', alpha=0.5)
|
| 287 |
+
ax.plot(angles, target_values, '#2ecc71', linestyle='--', linewidth=1, label='Meta', alpha=0.5)
|
| 288 |
+
ax.fill_between(angles, target_values, [1]*len(angles), color='#2ecc71', alpha=0.1)
|
| 289 |
+
ax.fill_between(angles, [0]*len(angles), min_values, color='#e74c3c', alpha=0.1)
|
| 290 |
|
| 291 |
+
# Dibujar valores del usuario
|
| 292 |
+
ax.plot(angles, values_user, '#3498db', linewidth=2, label='Tu escritura')
|
| 293 |
+
ax.fill(angles, values_user, '#3498db', alpha=0.2)
|
| 294 |
+
|
| 295 |
+
# Ajustar leyenda
|
| 296 |
+
ax.legend(
|
| 297 |
+
loc='upper right',
|
| 298 |
+
bbox_to_anchor=(0.1, 0.1),
|
| 299 |
+
fontsize=10,
|
| 300 |
+
frameon=True,
|
| 301 |
+
facecolor='white',
|
| 302 |
+
edgecolor='none',
|
| 303 |
+
shadow=True
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
plt.tight_layout()
|
| 307 |
+
st.pyplot(fig)
|
| 308 |
+
plt.close()
|
| 309 |
|
| 310 |
except Exception as e:
|
| 311 |
+
logger.error(f"Error mostrando gráfico radar: {str(e)}")
|
| 312 |
+
st.error("Error al mostrar el gráfico")
|
| 313 |
+
#######################################
|