Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -90,25 +90,26 @@ ANALYSIS_DIMENSION_MAPPING = {
|
|
90 |
}
|
91 |
}
|
92 |
|
|
|
93 |
##############################################################################
|
94 |
# FUNCIÓN PRINCIPAL
|
95 |
##############################################################################
|
96 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
97 |
"""
|
98 |
-
Distribución requerida:
|
99 |
TAB:
|
100 |
-
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
Fila 3: Recomendaciones
|
106 |
|
107 |
-
|
108 |
-
Col1: Texto base
|
109 |
-
Col2: Texto iteración
|
110 |
"""
|
111 |
-
# --- Inicializar
|
112 |
if 'base_text' not in st.session_state:
|
113 |
st.session_state.base_text = ""
|
114 |
if 'iter_text' not in st.session_state:
|
@@ -122,97 +123,118 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
122 |
if 'show_iter' not in st.session_state:
|
123 |
st.session_state.show_iter = False
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
)
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
with st.container():
|
170 |
-
|
171 |
-
|
172 |
-
#
|
173 |
-
|
174 |
-
|
175 |
-
text_base = st.text_area(
|
176 |
-
label="",
|
177 |
-
value=st.session_state.base_text,
|
178 |
-
key="text_base_area",
|
179 |
-
placeholder="Pega aquí tu texto base",
|
180 |
-
# Quitar 'height' si quieres permitir altura completamente flexible:
|
181 |
-
# height=200
|
182 |
-
)
|
183 |
-
|
184 |
-
if st.button("Analizar Base"):
|
185 |
-
with st.spinner("Analizando texto base..."):
|
186 |
-
doc = nlp_models[lang_code](text_base)
|
187 |
-
metrics = analyze_text_dimensions(doc)
|
188 |
-
st.session_state.base_text = text_base
|
189 |
-
st.session_state.base_metrics = metrics
|
190 |
-
st.session_state.show_base = True
|
191 |
-
st.session_state.show_iter = False
|
192 |
-
|
193 |
-
# Caja de texto para la iteración
|
194 |
-
with col_right:
|
195 |
-
st.markdown("**Texto de iteración**")
|
196 |
-
text_iter = st.text_area(
|
197 |
-
label="",
|
198 |
-
value=st.session_state.iter_text,
|
199 |
-
key="text_iter_area",
|
200 |
-
placeholder="Edita y mejora tu texto...",
|
201 |
-
disabled=not st.session_state.show_base,
|
202 |
-
# height=200
|
203 |
-
)
|
204 |
-
|
205 |
-
if st.button("Analizar Iteración", disabled=not st.session_state.show_base):
|
206 |
-
with st.spinner("Analizando texto de iteración..."):
|
207 |
-
doc = nlp_models[lang_code](text_iter)
|
208 |
-
metrics = analyze_text_dimensions(doc)
|
209 |
-
st.session_state.iter_text = text_iter
|
210 |
-
st.session_state.iter_metrics = metrics
|
211 |
-
st.session_state.show_iter = True
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
|
218 |
#Funciones de visualización ##################################
|
@@ -252,6 +274,7 @@ def display_metrics_in_one_line(metrics, text_type):
|
|
252 |
value=f"{score:.2f}",
|
253 |
delta=f"{status} (Meta: {target:.2f})",
|
254 |
delta_color=color
|
|
|
255 |
)
|
256 |
|
257 |
|
|
|
90 |
}
|
91 |
}
|
92 |
|
93 |
+
|
94 |
##############################################################################
|
95 |
# FUNCIÓN PRINCIPAL
|
96 |
##############################################################################
|
97 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
98 |
"""
|
|
|
99 |
TAB:
|
100 |
+
- Expander con radio para tipo de texto
|
101 |
+
|
102 |
+
Contenedor-1 (2 "filas" con borde):
|
103 |
+
- Fila 1: Métricas base
|
104 |
+
- Fila 2: Métricas iteración
|
105 |
|
106 |
+
Contenedor-2 (2 columnas):
|
107 |
+
- Col1: Texto base
|
108 |
+
- Col2: Texto iteración
|
|
|
109 |
|
110 |
+
Al final, Recomendaciones en una sola línea.
|
|
|
|
|
111 |
"""
|
112 |
+
# --- Inicializar session_state ---
|
113 |
if 'base_text' not in st.session_state:
|
114 |
st.session_state.base_text = ""
|
115 |
if 'iter_text' not in st.session_state:
|
|
|
123 |
if 'show_iter' not in st.session_state:
|
124 |
st.session_state.show_iter = False
|
125 |
|
126 |
+
# Creamos un TAB
|
127 |
+
tabs = st.tabs(["Análisis de Texto"])
|
128 |
+
with tabs[0]:
|
129 |
+
# 1) Expander con radio
|
130 |
+
with st.expander("Selecciona el tipo de texto", expanded=True):
|
131 |
+
text_type = st.radio(
|
132 |
+
"¿Qué tipo de texto quieres analizar?",
|
133 |
+
options=list(TEXT_TYPES.keys()),
|
134 |
+
format_func=lambda x: TEXT_TYPES[x]['name'],
|
135 |
+
index=0
|
136 |
+
)
|
137 |
+
st.session_state.current_text_type = text_type
|
138 |
+
|
139 |
+
st.markdown("---")
|
140 |
+
|
141 |
+
# ---------------------------------------------------------------------
|
142 |
+
# CONTENEDOR-1: Métricas (2 filas con borde)
|
143 |
+
# ---------------------------------------------------------------------
|
144 |
+
with st.container():
|
145 |
+
# Fila 1: Métricas base
|
146 |
+
if st.session_state.show_base:
|
147 |
+
# Usamos HTML + CSS para enmarcar las métricas en un div con borde
|
148 |
+
st.markdown(
|
149 |
+
"""
|
150 |
+
<div style="border:1px solid black; padding:10px; margin-bottom:10px;">
|
151 |
+
<p style="font-weight:bold;">Métricas de la línea base</p>
|
152 |
+
""",
|
153 |
+
unsafe_allow_html=True
|
154 |
)
|
155 |
+
# ---- Aquí llamamos a la función que muestra las 4 métricas ----
|
156 |
+
display_metrics_in_one_row(st.session_state.base_metrics, text_type)
|
157 |
+
# Cerramos el div
|
158 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
159 |
+
|
160 |
+
# Fila 2: Métricas de iteración
|
161 |
+
if st.session_state.show_iter:
|
162 |
+
st.markdown(
|
163 |
+
"""
|
164 |
+
<div style="border:1px solid black; padding:10px; margin-bottom:10px;">
|
165 |
+
<p style="font-weight:bold;">Métricas de la iteración</p>
|
166 |
+
""",
|
167 |
+
unsafe_allow_html=True
|
168 |
+
)
|
169 |
+
display_metrics_in_one_row(st.session_state.iter_metrics, text_type)
|
170 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
171 |
+
|
172 |
+
# ---------------------------------------------------------------------
|
173 |
+
# CONTENEDOR-2: 2 columnas (texto base | texto iteración)
|
174 |
+
# ---------------------------------------------------------------------
|
175 |
+
with st.container():
|
176 |
+
col_left, col_right = st.columns(2)
|
177 |
+
|
178 |
+
with col_left:
|
179 |
+
st.markdown("**Texto base**")
|
180 |
+
text_base = st.text_area(
|
181 |
+
label="",
|
182 |
+
value=st.session_state.base_text,
|
183 |
+
key="text_base_area",
|
184 |
+
placeholder="Pega aquí tu texto base"
|
185 |
+
)
|
186 |
+
if st.button("Analizar Base"):
|
187 |
+
with st.spinner("Analizando texto base..."):
|
188 |
+
doc = nlp_models[lang_code](text_base)
|
189 |
+
metrics = analyze_text_dimensions(doc)
|
190 |
+
st.session_state.base_text = text_base
|
191 |
+
st.session_state.base_metrics = metrics
|
192 |
+
st.session_state.show_base = True
|
193 |
+
# Al analizar base, reiniciamos la iteración
|
194 |
+
st.session_state.show_iter = False
|
195 |
+
|
196 |
+
with col_right:
|
197 |
+
st.markdown("**Texto de iteración**")
|
198 |
+
text_iter = st.text_area(
|
199 |
+
label="",
|
200 |
+
value=st.session_state.iter_text,
|
201 |
+
key="text_iter_area",
|
202 |
+
placeholder="Edita y mejora tu texto...",
|
203 |
+
disabled=not st.session_state.show_base
|
204 |
+
)
|
205 |
+
if st.button("Analizar Iteración", disabled=not st.session_state.show_base):
|
206 |
+
with st.spinner("Analizando iteración..."):
|
207 |
+
doc = nlp_models[lang_code](text_iter)
|
208 |
+
metrics = analyze_text_dimensions(doc)
|
209 |
+
st.session_state.iter_text = text_iter
|
210 |
+
st.session_state.iter_metrics = metrics
|
211 |
+
st.session_state.show_iter = True
|
212 |
+
|
213 |
+
# ---------------------------------------------------------------------
|
214 |
+
# Recomendaciones al final (una sola línea, por ejemplo)
|
215 |
+
# ---------------------------------------------------------------------
|
216 |
+
# Solo mostramos si tenemos iteración
|
217 |
+
if st.session_state.show_iter:
|
218 |
+
# Podríamos mostrar todo en una misma línea usando st.columns(1)
|
219 |
+
# o simplemente un st.container(). Lo muestro en un solo contenedor:
|
220 |
with st.container():
|
221 |
+
st.markdown("**Recomendaciones**")
|
222 |
+
# Si las quieres en una sola línea, podrías hacer algo como:
|
223 |
+
# rec_col = st.columns(1)[0] # Solo 1 columna
|
224 |
+
# con rec_col: ...
|
225 |
+
# Pero en general, un for con st.write estará apilado verticalmente.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
+
# Ejemplo de iterar dimensiones
|
228 |
+
any_reco = False
|
229 |
+
for dimension, values in st.session_state.iter_metrics.items():
|
230 |
+
score = values['normalized_score']
|
231 |
+
target = TEXT_TYPES[text_type]['thresholds'][dimension]['target']
|
232 |
+
if score < target:
|
233 |
+
suggest_improvement_tools(dimension)
|
234 |
+
any_reco = True
|
235 |
+
|
236 |
+
if not any_reco:
|
237 |
+
st.info("¡No hay recomendaciones! Todas las métricas superan la meta.")
|
238 |
|
239 |
|
240 |
#Funciones de visualización ##################################
|
|
|
274 |
value=f"{score:.2f}",
|
275 |
delta=f"{status} (Meta: {target:.2f})",
|
276 |
delta_color=color
|
277 |
+
border=True
|
278 |
)
|
279 |
|
280 |
|