Spaces:
Sleeping
Sleeping
Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# modules/studentact/current_situation_interface.py
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import logging
|
|
@@ -62,7 +62,8 @@ TEXT_TYPES = {
|
|
| 62 |
}
|
| 63 |
}
|
| 64 |
####################################
|
| 65 |
-
|
|
|
|
| 66 |
"""
|
| 67 |
Interfaz simplificada con gráfico de radar para visualizar métricas.
|
| 68 |
"""
|
|
@@ -86,11 +87,11 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
|
|
| 86 |
with input_col:
|
| 87 |
# Text area con manejo de estado
|
| 88 |
text_input = st.text_area(
|
| 89 |
-
|
| 90 |
height=400,
|
| 91 |
key="text_area",
|
| 92 |
value=st.session_state.text_input,
|
| 93 |
-
help=
|
| 94 |
)
|
| 95 |
|
| 96 |
# Función para manejar cambios de texto
|
|
@@ -99,13 +100,13 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
|
|
| 99 |
st.session_state.show_results = False
|
| 100 |
|
| 101 |
if st.button(
|
| 102 |
-
|
| 103 |
type="primary",
|
| 104 |
disabled=not text_input.strip(),
|
| 105 |
use_container_width=True,
|
| 106 |
):
|
| 107 |
try:
|
| 108 |
-
with st.spinner(
|
| 109 |
doc = nlp_models[lang_code](text_input)
|
| 110 |
metrics = analyze_text_dimensions(doc)
|
| 111 |
|
|
@@ -125,77 +126,116 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
|
|
| 125 |
|
| 126 |
except Exception as e:
|
| 127 |
logger.error(f"Error en análisis: {str(e)}")
|
| 128 |
-
st.error(
|
| 129 |
|
| 130 |
# Mostrar resultados en la columna derecha
|
| 131 |
with results_col:
|
| 132 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
| 133 |
# Primero los radio buttons para tipo de texto
|
| 134 |
-
st.markdown(
|
| 135 |
text_type = st.radio(
|
| 136 |
-
"
|
| 137 |
options=list(TEXT_TYPES.keys()),
|
| 138 |
format_func=lambda x: TEXT_TYPES[x]['name'],
|
| 139 |
horizontal=True,
|
| 140 |
key="text_type_radio",
|
| 141 |
-
help=
|
| 142 |
)
|
| 143 |
|
| 144 |
st.session_state.current_text_type = text_type
|
| 145 |
|
| 146 |
-
#
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
metrics_config = [
|
| 151 |
-
{
|
| 152 |
-
'label': current_situation_t.get('vocabulary_label', 'Vocabulario'),
|
| 153 |
-
'value': st.session_state.current_metrics['vocabulary'],
|
| 154 |
-
'thresholds': {
|
| 155 |
-
'min': thresholds['vocabulary']['min'],
|
| 156 |
-
'target': thresholds['vocabulary']['target']
|
| 157 |
-
}
|
| 158 |
-
},
|
| 159 |
-
{
|
| 160 |
-
'label': current_situation_t.get('structure_label', 'Estructura'),
|
| 161 |
-
'value': st.session_state.current_metrics['structure'],
|
| 162 |
-
'thresholds': {
|
| 163 |
-
'min': thresholds['structure']['min'],
|
| 164 |
-
'target': thresholds['structure']['target']
|
| 165 |
-
}
|
| 166 |
-
},
|
| 167 |
-
{
|
| 168 |
-
'label': current_situation_t.get('cohesion_label', 'Cohesión'),
|
| 169 |
-
'value': st.session_state.current_metrics['cohesion'],
|
| 170 |
-
'thresholds': {
|
| 171 |
-
'min': thresholds['cohesion']['min'],
|
| 172 |
-
'target': thresholds['cohesion']['target']
|
| 173 |
-
}
|
| 174 |
-
},
|
| 175 |
-
{
|
| 176 |
-
'label': current_situation_t.get('clarity_label', 'Claridad'),
|
| 177 |
-
'value': st.session_state.current_metrics['clarity'],
|
| 178 |
-
'thresholds': {
|
| 179 |
-
'min': thresholds['clarity']['min'],
|
| 180 |
-
'target': thresholds['clarity']['target']
|
| 181 |
-
}
|
| 182 |
-
}
|
| 183 |
-
]
|
| 184 |
-
|
| 185 |
-
# Usar la función display_radar_chart que ya existe
|
| 186 |
-
display_radar_chart(
|
| 187 |
-
metrics_config=metrics_config,
|
| 188 |
-
thresholds=thresholds,
|
| 189 |
-
current_situation_t=current_situation_t
|
| 190 |
)
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
| 194 |
-
st.error(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
|
| 197 |
######################################
|
| 198 |
-
def display_radar_chart(metrics_config, thresholds
|
| 199 |
"""
|
| 200 |
Muestra el gráfico radar con los resultados.
|
| 201 |
"""
|
|
@@ -238,7 +278,7 @@ def display_radar_chart(metrics_config, thresholds, current_situation_t):
|
|
| 238 |
# Ajustar leyenda
|
| 239 |
ax.legend(
|
| 240 |
loc='upper right',
|
| 241 |
-
bbox_to_anchor=(1.3, 1.1),
|
| 242 |
fontsize=10,
|
| 243 |
frameon=True,
|
| 244 |
facecolor='white',
|
|
@@ -252,5 +292,5 @@ def display_radar_chart(metrics_config, thresholds, current_situation_t):
|
|
| 252 |
|
| 253 |
except Exception as e:
|
| 254 |
logger.error(f"Error mostrando gráfico radar: {str(e)}")
|
| 255 |
-
st.error(
|
| 256 |
#######################################
|
|
|
|
| 1 |
+
# modules/studentact/current_situation_interface-vOK.py
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import logging
|
|
|
|
| 62 |
}
|
| 63 |
}
|
| 64 |
####################################
|
| 65 |
+
|
| 66 |
+
def display_current_situation_interface(lang_code, nlp_models, t):
|
| 67 |
"""
|
| 68 |
Interfaz simplificada con gráfico de radar para visualizar métricas.
|
| 69 |
"""
|
|
|
|
| 87 |
with input_col:
|
| 88 |
# Text area con manejo de estado
|
| 89 |
text_input = st.text_area(
|
| 90 |
+
t.get('input_prompt', "Escribe o pega tu texto aquí:"),
|
| 91 |
height=400,
|
| 92 |
key="text_area",
|
| 93 |
value=st.session_state.text_input,
|
| 94 |
+
help="Este texto será analizado para darte recomendaciones personalizadas"
|
| 95 |
)
|
| 96 |
|
| 97 |
# Función para manejar cambios de texto
|
|
|
|
| 100 |
st.session_state.show_results = False
|
| 101 |
|
| 102 |
if st.button(
|
| 103 |
+
t.get('analyze_button', "Analizar mi escritura"),
|
| 104 |
type="primary",
|
| 105 |
disabled=not text_input.strip(),
|
| 106 |
use_container_width=True,
|
| 107 |
):
|
| 108 |
try:
|
| 109 |
+
with st.spinner(t.get('processing', "Analizando...")):
|
| 110 |
doc = nlp_models[lang_code](text_input)
|
| 111 |
metrics = analyze_text_dimensions(doc)
|
| 112 |
|
|
|
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
logger.error(f"Error en análisis: {str(e)}")
|
| 129 |
+
st.error(t.get('analysis_error', "Error al analizar el texto"))
|
| 130 |
|
| 131 |
# Mostrar resultados en la columna derecha
|
| 132 |
with results_col:
|
| 133 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
| 134 |
# Primero los radio buttons para tipo de texto
|
| 135 |
+
st.markdown("### Tipo de texto")
|
| 136 |
text_type = st.radio(
|
| 137 |
+
"",
|
| 138 |
options=list(TEXT_TYPES.keys()),
|
| 139 |
format_func=lambda x: TEXT_TYPES[x]['name'],
|
| 140 |
horizontal=True,
|
| 141 |
key="text_type_radio",
|
| 142 |
+
help="Selecciona el tipo de texto para ajustar los criterios de evaluación"
|
| 143 |
)
|
| 144 |
|
| 145 |
st.session_state.current_text_type = text_type
|
| 146 |
|
| 147 |
+
# Luego mostrar los resultados
|
| 148 |
+
display_results(
|
| 149 |
+
metrics=st.session_state.current_metrics,
|
| 150 |
+
text_type=text_type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
)
|
| 152 |
|
| 153 |
except Exception as e:
|
| 154 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
| 155 |
+
st.error("Ocurrió un error al cargar la interfaz")
|
| 156 |
+
|
| 157 |
+
###################################3333
|
| 158 |
+
|
| 159 |
+
def display_results(metrics, text_type=None):
|
| 160 |
+
"""
|
| 161 |
+
Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
|
| 162 |
+
"""
|
| 163 |
+
try:
|
| 164 |
+
# Usar valor por defecto si no se especifica tipo
|
| 165 |
+
text_type = text_type or 'student_essay'
|
| 166 |
+
|
| 167 |
+
# Obtener umbrales según el tipo de texto
|
| 168 |
+
thresholds = TEXT_TYPES[text_type]['thresholds']
|
| 169 |
+
|
| 170 |
+
# Crear dos columnas para las métricas y el gráfico
|
| 171 |
+
metrics_col, graph_col = st.columns([1, 1.5])
|
| 172 |
+
|
| 173 |
+
# Columna de métricas
|
| 174 |
+
with metrics_col:
|
| 175 |
+
metrics_config = [
|
| 176 |
+
{
|
| 177 |
+
'label': "Vocabulario",
|
| 178 |
+
'key': 'vocabulary',
|
| 179 |
+
'value': metrics['vocabulary']['normalized_score'],
|
| 180 |
+
'help': "Riqueza y variedad del vocabulario",
|
| 181 |
+
'thresholds': thresholds['vocabulary']
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
'label': "Estructura",
|
| 185 |
+
'key': 'structure',
|
| 186 |
+
'value': metrics['structure']['normalized_score'],
|
| 187 |
+
'help': "Organización y complejidad de oraciones",
|
| 188 |
+
'thresholds': thresholds['structure']
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
'label': "Cohesión",
|
| 192 |
+
'key': 'cohesion',
|
| 193 |
+
'value': metrics['cohesion']['normalized_score'],
|
| 194 |
+
'help': "Conexión y fluidez entre ideas",
|
| 195 |
+
'thresholds': thresholds['cohesion']
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
'label': "Claridad",
|
| 199 |
+
'key': 'clarity',
|
| 200 |
+
'value': metrics['clarity']['normalized_score'],
|
| 201 |
+
'help': "Facilidad de comprensión del texto",
|
| 202 |
+
'thresholds': thresholds['clarity']
|
| 203 |
+
}
|
| 204 |
+
]
|
| 205 |
+
|
| 206 |
+
# Mostrar métricas
|
| 207 |
+
for metric in metrics_config:
|
| 208 |
+
value = metric['value']
|
| 209 |
+
if value < metric['thresholds']['min']:
|
| 210 |
+
status = "⚠️ Por mejorar"
|
| 211 |
+
color = "inverse"
|
| 212 |
+
elif value < metric['thresholds']['target']:
|
| 213 |
+
status = "📈 Aceptable"
|
| 214 |
+
color = "off"
|
| 215 |
+
else:
|
| 216 |
+
status = "✅ Óptimo"
|
| 217 |
+
color = "normal"
|
| 218 |
+
|
| 219 |
+
st.metric(
|
| 220 |
+
metric['label'],
|
| 221 |
+
f"{value:.2f}",
|
| 222 |
+
f"{status} (Meta: {metric['thresholds']['target']:.2f})",
|
| 223 |
+
delta_color=color,
|
| 224 |
+
help=metric['help']
|
| 225 |
+
)
|
| 226 |
+
st.markdown("<div style='margin-bottom: 0.5rem;'></div>", unsafe_allow_html=True)
|
| 227 |
+
|
| 228 |
+
# Gráfico radar en la columna derecha
|
| 229 |
+
with graph_col:
|
| 230 |
+
display_radar_chart(metrics_config, thresholds)
|
| 231 |
+
|
| 232 |
+
except Exception as e:
|
| 233 |
+
logger.error(f"Error mostrando resultados: {str(e)}")
|
| 234 |
+
st.error("Error al mostrar los resultados")
|
| 235 |
|
| 236 |
|
| 237 |
######################################
|
| 238 |
+
def display_radar_chart(metrics_config, thresholds):
|
| 239 |
"""
|
| 240 |
Muestra el gráfico radar con los resultados.
|
| 241 |
"""
|
|
|
|
| 278 |
# Ajustar leyenda
|
| 279 |
ax.legend(
|
| 280 |
loc='upper right',
|
| 281 |
+
bbox_to_anchor=(1.3, 1.1), # Cambiado de (0.1, 0.1) a (1.3, 1.1)
|
| 282 |
fontsize=10,
|
| 283 |
frameon=True,
|
| 284 |
facecolor='white',
|
|
|
|
| 292 |
|
| 293 |
except Exception as e:
|
| 294 |
logger.error(f"Error mostrando gráfico radar: {str(e)}")
|
| 295 |
+
st.error("Error al mostrar el gráfico")
|
| 296 |
#######################################
|