Spaces:
Running
Running
Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
|
@@ -48,46 +48,20 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
| 48 |
if 'current_metrics' not in st.session_state:
|
| 49 |
st.session_state.current_metrics = None
|
| 50 |
|
| 51 |
-
|
| 52 |
-
st.markdown("""
|
| 53 |
-
<style>
|
| 54 |
-
.main-title {
|
| 55 |
-
margin-bottom: 2rem;
|
| 56 |
-
}
|
| 57 |
-
.stTextArea textarea {
|
| 58 |
-
border-radius: 0.5rem;
|
| 59 |
-
}
|
| 60 |
-
div[data-testid="column"] {
|
| 61 |
-
background-color: transparent;
|
| 62 |
-
}
|
| 63 |
-
.metric-container {
|
| 64 |
-
background-color: #f8f9fa;
|
| 65 |
-
padding: 1rem;
|
| 66 |
-
border-radius: 0.5rem;
|
| 67 |
-
margin-bottom: 1rem;
|
| 68 |
-
}
|
| 69 |
-
</style>
|
| 70 |
-
""", unsafe_allow_html=True)
|
| 71 |
-
|
| 72 |
-
st.markdown('<h2 class="main-title">An谩lisis Inicial de Escritura</h2>', unsafe_allow_html=True)
|
| 73 |
|
| 74 |
# Container principal con dos columnas
|
| 75 |
with st.container():
|
| 76 |
input_col, results_col = st.columns([1,2])
|
| 77 |
|
| 78 |
with input_col:
|
| 79 |
-
# Funci贸n para manejar cambios en el texto
|
| 80 |
-
def on_text_change():
|
| 81 |
-
st.session_state.text_input = st.session_state.text_area
|
| 82 |
-
st.session_state.show_results = False
|
| 83 |
-
|
| 84 |
# Text area con manejo de estado
|
| 85 |
text_input = st.text_area(
|
| 86 |
t.get('input_prompt', "Escribe o pega tu texto aqu铆:"),
|
| 87 |
height=400,
|
| 88 |
key="text_area",
|
| 89 |
value=st.session_state.text_input,
|
| 90 |
-
on_change=on_text_change,
|
| 91 |
help="Este texto ser谩 analizado para darte recomendaciones personalizadas"
|
| 92 |
)
|
| 93 |
|
|
@@ -125,74 +99,87 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
| 125 |
# Mostrar resultados en la columna derecha
|
| 126 |
with results_col:
|
| 127 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
| 128 |
-
|
| 129 |
|
| 130 |
except Exception as e:
|
| 131 |
logger.error(f"Error en interfaz: {str(e)}")
|
| 132 |
st.error("Ocurri贸 un error. Por favor, intente de nuevo.")
|
| 133 |
|
| 134 |
-
|
| 135 |
-
########################################
|
| 136 |
-
def display_radar_chart(metrics):
|
| 137 |
"""
|
| 138 |
-
Muestra
|
| 139 |
"""
|
| 140 |
try:
|
| 141 |
-
# Container con proporci贸n reducida
|
| 142 |
with st.container():
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
with c2:
|
| 157 |
-
st.metric(
|
| 158 |
-
"Estructura",
|
| 159 |
-
f"{metrics['structure']['normalized_score']:.2f}",
|
| 160 |
-
"Meta: 1.00",
|
| 161 |
-
delta_color="off",
|
| 162 |
-
help="Organizaci贸n y complejidad de las oraciones"
|
| 163 |
-
)
|
| 164 |
-
with c3:
|
| 165 |
-
st.metric(
|
| 166 |
-
"Cohesi贸n",
|
| 167 |
-
f"{metrics['cohesion']['normalized_score']:.2f}",
|
| 168 |
-
"Meta: 1.00",
|
| 169 |
-
delta_color="off",
|
| 170 |
-
help="Conexi贸n y fluidez entre ideas"
|
| 171 |
-
)
|
| 172 |
-
with c4:
|
| 173 |
-
st.metric(
|
| 174 |
-
"Claridad",
|
| 175 |
-
f"{metrics['clarity']['normalized_score']:.2f}",
|
| 176 |
-
"Meta: 1.00",
|
| 177 |
-
delta_color="off",
|
| 178 |
-
help="Facilidad de comprensi贸n del texto"
|
| 179 |
-
)
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
with graph_col:
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
# Crear figura m谩s compacta
|
| 198 |
fig = plt.figure(figsize=(6, 6))
|
|
|
|
| 48 |
if 'current_metrics' not in st.session_state:
|
| 49 |
st.session_state.current_metrics = None
|
| 50 |
|
| 51 |
+
st.markdown("## An谩lisis Inicial de Escritura")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Container principal con dos columnas
|
| 54 |
with st.container():
|
| 55 |
input_col, results_col = st.columns([1,2])
|
| 56 |
|
| 57 |
with input_col:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Text area con manejo de estado
|
| 59 |
text_input = st.text_area(
|
| 60 |
t.get('input_prompt', "Escribe o pega tu texto aqu铆:"),
|
| 61 |
height=400,
|
| 62 |
key="text_area",
|
| 63 |
value=st.session_state.text_input,
|
| 64 |
+
on_change=lambda: on_text_change(),
|
| 65 |
help="Este texto ser谩 analizado para darte recomendaciones personalizadas"
|
| 66 |
)
|
| 67 |
|
|
|
|
| 99 |
# Mostrar resultados en la columna derecha
|
| 100 |
with results_col:
|
| 101 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
| 102 |
+
display_metrics_and_chart(st.session_state.current_metrics)
|
| 103 |
|
| 104 |
except Exception as e:
|
| 105 |
logger.error(f"Error en interfaz: {str(e)}")
|
| 106 |
st.error("Ocurri贸 un error. Por favor, intente de nuevo.")
|
| 107 |
|
| 108 |
+
def display_metrics_and_chart(metrics):
|
|
|
|
|
|
|
| 109 |
"""
|
| 110 |
+
Muestra las m茅tricas y el gr谩fico de radar de manera organizada.
|
| 111 |
"""
|
| 112 |
try:
|
|
|
|
| 113 |
with st.container():
|
| 114 |
+
# Crear una fila de m茅tricas con bordes y alineaci贸n uniforme
|
| 115 |
+
metric_cols = st.columns(4, gap="small", vertical_alignment="center", border=True)
|
| 116 |
|
| 117 |
+
# Vocabulario
|
| 118 |
+
metric_cols[0].metric(
|
| 119 |
+
"Vocabulario",
|
| 120 |
+
f"{metrics['vocabulary']['normalized_score']:.2f}",
|
| 121 |
+
"Meta: 1.00",
|
| 122 |
+
delta_color="off",
|
| 123 |
+
help="Riqueza y variedad del vocabulario utilizado"
|
| 124 |
+
)
|
| 125 |
|
| 126 |
+
# Estructura
|
| 127 |
+
metric_cols[1].metric(
|
| 128 |
+
"Estructura",
|
| 129 |
+
f"{metrics['structure']['normalized_score']:.2f}",
|
| 130 |
+
"Meta: 1.00",
|
| 131 |
+
delta_color="off",
|
| 132 |
+
help="Organizaci贸n y complejidad de las oraciones"
|
| 133 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
# Cohesi贸n
|
| 136 |
+
metric_cols[2].metric(
|
| 137 |
+
"Cohesi贸n",
|
| 138 |
+
f"{metrics['cohesion']['normalized_score']:.2f}",
|
| 139 |
+
"Meta: 1.00",
|
| 140 |
+
delta_color="off",
|
| 141 |
+
help="Conexi贸n y fluidez entre ideas"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
# Claridad
|
| 145 |
+
metric_cols[3].metric(
|
| 146 |
+
"Claridad",
|
| 147 |
+
f"{metrics['clarity']['normalized_score']:.2f}",
|
| 148 |
+
"Meta: 1.00",
|
| 149 |
+
delta_color="off",
|
| 150 |
+
help="Facilidad de comprensi贸n del texto"
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
# Espacio para separar m茅tricas del gr谩fico
|
| 154 |
+
st.markdown("<div style='margin-top: 1rem;'></div>", unsafe_allow_html=True)
|
| 155 |
+
|
| 156 |
+
# Contenedor para el gr谩fico radar centrado
|
| 157 |
+
with st.container():
|
| 158 |
+
# Usar columnas para centrar el gr谩fico
|
| 159 |
+
left_space, graph_col, right_space = st.columns([1, 2, 1])
|
| 160 |
|
| 161 |
with graph_col:
|
| 162 |
+
display_radar_chart(metrics)
|
| 163 |
+
|
| 164 |
+
except Exception as e:
|
| 165 |
+
logger.error(f"Error mostrando m茅tricas y gr谩fico: {str(e)}")
|
| 166 |
+
st.error("Error al mostrar los resultados")
|
| 167 |
+
|
| 168 |
+
########################################
|
| 169 |
+
def display_radar_chart(metrics):
|
| 170 |
+
"""
|
| 171 |
+
Muestra solo el gr谩fico de radar.
|
| 172 |
+
"""
|
| 173 |
+
try:
|
| 174 |
+
# Preparar datos para el gr谩fico
|
| 175 |
+
categories = ['Vocabulario', 'Estructura', 'Cohesi贸n', 'Claridad']
|
| 176 |
+
values_user = [
|
| 177 |
+
metrics['vocabulary']['normalized_score'],
|
| 178 |
+
metrics['structure']['normalized_score'],
|
| 179 |
+
metrics['cohesion']['normalized_score'],
|
| 180 |
+
metrics['clarity']['normalized_score']
|
| 181 |
+
]
|
| 182 |
+
values_pattern = [1.0, 1.0, 1.0, 1.0]
|
| 183 |
|
| 184 |
# Crear figura m谩s compacta
|
| 185 |
fig = plt.figure(figsize=(6, 6))
|