Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -90,123 +90,126 @@ ANALYSIS_DIMENSION_MAPPING = {
|
|
90 |
}
|
91 |
}
|
92 |
|
93 |
-
|
94 |
-
|
|
|
|
|
95 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
96 |
"""
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
"""
|
104 |
# --- Inicializar estados si no existen ---
|
105 |
-
if 'text_input' not in st.session_state:
|
106 |
-
st.session_state.text_input = ""
|
107 |
-
if 'text_area' not in st.session_state:
|
108 |
-
st.session_state.text_area = ""
|
109 |
-
if 'show_results' not in st.session_state:
|
110 |
-
st.session_state.show_results = False
|
111 |
-
if 'current_doc' not in st.session_state:
|
112 |
-
st.session_state.current_doc = None
|
113 |
-
if 'current_metrics' not in st.session_state:
|
114 |
-
st.session_state.current_metrics = None
|
115 |
if 'base_text' not in st.session_state:
|
116 |
st.session_state.base_text = ""
|
117 |
if 'iter_text' not in st.session_state:
|
118 |
st.session_state.iter_text = ""
|
|
|
|
|
|
|
|
|
119 |
if 'show_base' not in st.session_state:
|
120 |
st.session_state.show_base = False
|
121 |
if 'show_iter' not in st.session_state:
|
122 |
st.session_state.show_iter = False
|
123 |
|
124 |
try:
|
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 |
-
st.
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
#
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
st.
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
210 |
|
211 |
except Exception as e:
|
212 |
logger.error(f"Error en interfaz: {str(e)}")
|
@@ -214,42 +217,7 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
214 |
|
215 |
#Funciones de visualización ##################################
|
216 |
|
217 |
-
|
218 |
-
"""
|
219 |
-
Muestra las cuatro dimensiones (Vocabulario, Estructura, Cohesión, Claridad)
|
220 |
-
en una sola línea, usando 4 columnas.
|
221 |
-
"""
|
222 |
-
thresholds = TEXT_TYPES[text_type]['thresholds']
|
223 |
-
dimensions = ["vocabulary", "structure", "cohesion", "clarity"]
|
224 |
-
|
225 |
-
# Creamos 4 columnas
|
226 |
-
col1, col2, col3, col4 = st.columns(4)
|
227 |
-
cols = [col1, col2, col3, col4]
|
228 |
-
|
229 |
-
for dim, col in zip(dimensions, cols):
|
230 |
-
score = metrics[dim]['normalized_score']
|
231 |
-
target = thresholds[dim]['target']
|
232 |
-
min_val = thresholds[dim]['min']
|
233 |
-
|
234 |
-
# Determinar estado y color
|
235 |
-
if score < min_val:
|
236 |
-
status = "⚠️ Por mejorar"
|
237 |
-
color = "inverse"
|
238 |
-
elif score < target:
|
239 |
-
status = "📈 Aceptable"
|
240 |
-
color = "off"
|
241 |
-
else:
|
242 |
-
status = "✅ Óptimo"
|
243 |
-
color = "normal"
|
244 |
-
|
245 |
-
with col:
|
246 |
-
# Muestra la métrica con un st.metric
|
247 |
-
col.metric(
|
248 |
-
label=dim.capitalize(),
|
249 |
-
value=f"{score:.2f}",
|
250 |
-
delta=f"{status} (Meta: {target:.2f})",
|
251 |
-
delta_color=color
|
252 |
-
)
|
253 |
|
254 |
##################################################################
|
255 |
def display_metrics_analysis(metrics, text_type=None):
|
|
|
90 |
}
|
91 |
}
|
92 |
|
93 |
+
################################################################
|
94 |
+
##############################################################################
|
95 |
+
# FUNCIÓN PRINCIPAL
|
96 |
+
##############################################################################
|
97 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
98 |
"""
|
99 |
+
Distribución requerida:
|
100 |
+
TAB:
|
101 |
+
└─ Expander para seleccionar el tipo de texto
|
102 |
+
|
103 |
+
Contenedor-1 (tres filas):
|
104 |
+
Fila 1: Métricas de la línea base
|
105 |
+
Fila 2: Métricas de iteración
|
106 |
+
Fila 3: Recomendaciones
|
107 |
+
|
108 |
+
Contenedor-2 (dos columnas):
|
109 |
+
Col1: Texto base
|
110 |
+
Col2: Texto iteración
|
111 |
"""
|
112 |
# --- Inicializar estados si no existen ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
if 'base_text' not in st.session_state:
|
114 |
st.session_state.base_text = ""
|
115 |
if 'iter_text' not in st.session_state:
|
116 |
st.session_state.iter_text = ""
|
117 |
+
if 'base_metrics' not in st.session_state:
|
118 |
+
st.session_state.base_metrics = {}
|
119 |
+
if 'iter_metrics' not in st.session_state:
|
120 |
+
st.session_state.iter_metrics = {}
|
121 |
if 'show_base' not in st.session_state:
|
122 |
st.session_state.show_base = False
|
123 |
if 'show_iter' not in st.session_state:
|
124 |
st.session_state.show_iter = False
|
125 |
|
126 |
try:
|
127 |
+
# Creamos un tab
|
128 |
+
tabs = st.tabs(["Análisis de Texto"])
|
129 |
+
with tabs[0]:
|
130 |
+
# -----------------------------------------------------------------
|
131 |
+
# [1] Expander para seleccionar el tipo de texto
|
132 |
+
# -----------------------------------------------------------------
|
133 |
+
with st.expander("Selecciona el tipo de texto", expanded=True):
|
134 |
+
text_type = st.radio(
|
135 |
+
"¿Qué tipo de texto quieres analizar?",
|
136 |
+
options=list(TEXT_TYPES.keys()),
|
137 |
+
format_func=lambda x: TEXT_TYPES[x]['name'],
|
138 |
+
index=0,
|
139 |
+
help="Selecciona el tipo de texto para ajustar criterios de evaluación"
|
140 |
+
)
|
141 |
+
st.session_state.current_text_type = text_type
|
142 |
+
|
143 |
+
# -----------------------------------------------------------------
|
144 |
+
# Contenedor-1: 3 filas (Métricas base, Métricas iteración, Recomendaciones)
|
145 |
+
# -----------------------------------------------------------------
|
146 |
+
with st.container():
|
147 |
+
# --- Fila 1: Métricas base ---
|
148 |
+
if st.session_state.show_base:
|
149 |
+
st.markdown("**Métricas de la línea base del texto**")
|
150 |
+
display_metrics_in_one_line(st.session_state.base_metrics, text_type)
|
151 |
+
|
152 |
+
# --- Fila 2: Métricas iteración ---
|
153 |
+
if st.session_state.show_iter:
|
154 |
+
st.markdown("**Métricas de la iteración del texto**")
|
155 |
+
display_metrics_in_one_line(st.session_state.iter_metrics, text_type)
|
156 |
+
|
157 |
+
# --- Fila 3: Recomendaciones ---
|
158 |
+
# (Separado de las métricas, pero en la misma sección)
|
159 |
+
if st.session_state.show_iter:
|
160 |
+
st.markdown("**Recomendaciones**")
|
161 |
+
for dimension, values in st.session_state.iter_metrics.items():
|
162 |
+
score = values['normalized_score']
|
163 |
+
target = TEXT_TYPES[text_type]['thresholds'][dimension]['target']
|
164 |
+
if score < target:
|
165 |
+
suggest_improvement_tools(dimension)
|
166 |
+
|
167 |
+
# -----------------------------------------------------------------
|
168 |
+
# Contenedor-2: 2 columnas para ingresar texto base / iteración
|
169 |
+
# -----------------------------------------------------------------
|
170 |
+
with st.container():
|
171 |
+
col_left, col_right = st.columns(2)
|
172 |
+
|
173 |
+
# Caja de texto para el texto base
|
174 |
+
with col_left:
|
175 |
+
st.markdown("**Texto base**")
|
176 |
+
text_base = st.text_area(
|
177 |
+
label="",
|
178 |
+
value=st.session_state.base_text,
|
179 |
+
key="text_base_area",
|
180 |
+
placeholder="Pega aquí tu texto base",
|
181 |
+
# Quitar 'height' si quieres permitir altura completamente flexible:
|
182 |
+
# height=200
|
183 |
+
)
|
184 |
+
|
185 |
+
if st.button("Analizar Base"):
|
186 |
+
with st.spinner("Analizando texto base..."):
|
187 |
+
doc = nlp_models[lang_code](text_base)
|
188 |
+
metrics = analyze_text_dimensions(doc)
|
189 |
+
st.session_state.base_text = text_base
|
190 |
+
st.session_state.base_metrics = metrics
|
191 |
+
st.session_state.show_base = True
|
192 |
+
st.session_state.show_iter = False
|
193 |
+
|
194 |
+
# Caja de texto para la iteración
|
195 |
+
with col_right:
|
196 |
+
st.markdown("**Texto de iteración**")
|
197 |
+
text_iter = st.text_area(
|
198 |
+
label="",
|
199 |
+
value=st.session_state.iter_text,
|
200 |
+
key="text_iter_area",
|
201 |
+
placeholder="Edita y mejora tu texto...",
|
202 |
+
disabled=not st.session_state.show_base,
|
203 |
+
# height=200
|
204 |
+
)
|
205 |
+
|
206 |
+
if st.button("Analizar Iteración", disabled=not st.session_state.show_base):
|
207 |
+
with st.spinner("Analizando texto de iteración..."):
|
208 |
+
doc = nlp_models[lang_code](text_iter)
|
209 |
+
metrics = analyze_text_dimensions(doc)
|
210 |
+
st.session_state.iter_text = text_iter
|
211 |
+
st.session_state.iter_metrics = metrics
|
212 |
+
st.session_state.show_iter = True
|
213 |
|
214 |
except Exception as e:
|
215 |
logger.error(f"Error en interfaz: {str(e)}")
|
|
|
217 |
|
218 |
#Funciones de visualización ##################################
|
219 |
|
220 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
##################################################################
|
223 |
def display_metrics_analysis(metrics, text_type=None):
|