Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -94,161 +94,92 @@ ANALYSIS_DIMENSION_MAPPING = {
|
|
94 |
|
95 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
96 |
"""
|
97 |
-
Interfaz con
|
98 |
"""
|
99 |
# Inicializar estados si no existen
|
100 |
-
if '
|
101 |
-
st.session_state.
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
if '
|
107 |
-
st.session_state.
|
108 |
-
|
109 |
-
|
110 |
-
st.session_state.show_iteration_results = False
|
111 |
-
|
112 |
-
if 'base_doc' not in st.session_state:
|
113 |
-
st.session_state.base_doc = None
|
114 |
-
|
115 |
-
if 'iteration_doc' not in st.session_state:
|
116 |
-
st.session_state.iteration_doc = None
|
117 |
-
|
118 |
-
if 'base_metrics' not in st.session_state:
|
119 |
-
st.session_state.base_metrics = None
|
120 |
-
|
121 |
-
if 'iteration_metrics' not in st.session_state:
|
122 |
-
st.session_state.iteration_metrics = None
|
123 |
-
|
124 |
-
try:
|
125 |
-
with st.spinner(t.get('processing_base', "Analizando l铆nea base...")):
|
126 |
-
doc = nlp_models[lang_code](text_base)
|
127 |
-
metrics = analyze_text_dimensions(doc)
|
128 |
-
|
129 |
-
storage_success = store_current_situation_result(
|
130 |
-
username=st.session_state.username,
|
131 |
-
text=text_base,
|
132 |
-
metrics=metrics,
|
133 |
-
feedback=None,
|
134 |
-
analysis_type='base'
|
135 |
-
)
|
136 |
|
137 |
-
|
|
|
138 |
with st.container():
|
139 |
-
# Crear
|
140 |
-
text_base_col,
|
141 |
-
|
142 |
-
#
|
143 |
with text_base_col:
|
144 |
-
|
145 |
-
|
|
|
146 |
height=400,
|
147 |
key="text_area_base",
|
148 |
-
value=st.session_state.
|
149 |
-
help="Este texto servir谩 como l铆nea base
|
150 |
)
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
st.session_state.text_base = text_base
|
155 |
-
st.session_state.show_base_results = False
|
156 |
-
|
157 |
-
if st.button(
|
158 |
-
t.get('analyze_base_button', "Establecer L铆nea Base"),
|
159 |
type="primary",
|
160 |
-
disabled=not
|
161 |
-
use_container_width=True
|
162 |
-
)
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
)
|
175 |
-
|
176 |
-
if not storage_success:
|
177 |
-
logger.warning("No se pudo guardar el an谩lisis base en la base de datos")
|
178 |
-
|
179 |
-
st.session_state.base_doc = doc
|
180 |
-
st.session_state.base_metrics = metrics
|
181 |
-
st.session_state.show_base_results = True
|
182 |
-
except Exception as e:
|
183 |
-
logger.error(f"Error en an谩lisis base: {str(e)}")
|
184 |
-
st.error(t.get('analysis_error', "Error al analizar el texto base"))
|
185 |
-
|
186 |
-
# COLUMNA 2: Resultados Base
|
187 |
-
with metrics_base_col:
|
188 |
-
if st.session_state.show_base_results and st.session_state.base_metrics is not None:
|
189 |
-
st.markdown("### M茅tricas Base")
|
190 |
-
display_results(
|
191 |
-
metrics=st.session_state.base_metrics,
|
192 |
-
text_type=st.session_state.get('current_text_type', 'student_essay')
|
193 |
-
)
|
194 |
-
|
195 |
-
# COLUMNA 3: Texto Iteraci贸n
|
196 |
with text_iter_col:
|
197 |
-
|
198 |
-
|
|
|
199 |
height=400,
|
200 |
key="text_area_iter",
|
201 |
-
|
202 |
-
help="Este texto ser谩 comparado con la l铆nea base",
|
203 |
-
disabled=not st.session_state.show_base_results
|
204 |
)
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
st.session_state.text_iteration = text_iter
|
209 |
-
st.session_state.show_iteration_results = False
|
210 |
-
|
211 |
-
if st.button(
|
212 |
-
t.get('analyze_iter_button', "Analizar Iteraci贸n"),
|
213 |
type="primary",
|
214 |
-
disabled=not
|
215 |
-
use_container_width=True
|
216 |
-
)
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
st.session_state.iteration_metrics = metrics
|
235 |
-
st.session_state.show_iteration_results = True
|
236 |
-
except Exception as e:
|
237 |
-
logger.error(f"Error en an谩lisis de iteraci贸n: {str(e)}")
|
238 |
-
st.error(t.get('analysis_error', "Error al analizar la iteraci贸n"))
|
239 |
-
|
240 |
-
# COLUMNA 4: Resultados Iteraci贸n
|
241 |
-
with metrics_iter_col:
|
242 |
-
if st.session_state.show_iteration_results and st.session_state.iteration_metrics is not None:
|
243 |
-
st.markdown("### M茅tricas Iteraci贸n")
|
244 |
-
display_results(
|
245 |
-
metrics=st.session_state.iteration_metrics,
|
246 |
-
text_type=st.session_state.get('current_text_type', 'student_essay')
|
247 |
)
|
248 |
-
|
249 |
except Exception as e:
|
250 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
251 |
st.error("Ocurri贸 un error al cargar la interfaz")
|
|
|
252 |
|
253 |
###################################
|
254 |
|
|
|
94 |
|
95 |
def display_current_situation_interface(lang_code, nlp_models, t):
|
96 |
"""
|
97 |
+
Interfaz simplificada con gr谩fico de radar para visualizar m茅tricas.
|
98 |
"""
|
99 |
# Inicializar estados si no existen
|
100 |
+
if 'text_input' not in st.session_state:
|
101 |
+
st.session_state.text_input = ""
|
102 |
+
if 'text_area' not in st.session_state:
|
103 |
+
st.session_state.text_area = ""
|
104 |
+
if 'show_results' not in st.session_state:
|
105 |
+
st.session_state.show_results = False
|
106 |
+
if 'current_doc' not in st.session_state:
|
107 |
+
st.session_state.current_doc = None
|
108 |
+
if 'current_metrics' not in st.session_state:
|
109 |
+
st.session_state.current_metrics = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
try:
|
112 |
+
# Container principal para las columnas
|
113 |
with st.container():
|
114 |
+
# Crear cuatro columnas con distribuci贸n equitativa
|
115 |
+
text_base_col, results_base_col, text_iter_col, results_iter_col = st.columns(4)
|
116 |
+
|
117 |
+
# Columna 1: Texto Base
|
118 |
with text_base_col:
|
119 |
+
st.markdown("### Texto Base")
|
120 |
+
text_input = st.text_area(
|
121 |
+
"Escribe o pega tu texto aqu铆:",
|
122 |
height=400,
|
123 |
key="text_area_base",
|
124 |
+
value=st.session_state.text_input,
|
125 |
+
help="Este texto servir谩 como l铆nea base"
|
126 |
)
|
127 |
+
|
128 |
+
baseline_button = st.button(
|
129 |
+
"Establecer L铆nea Base",
|
|
|
|
|
|
|
|
|
|
|
130 |
type="primary",
|
131 |
+
disabled=not text_input.strip(),
|
132 |
+
use_container_width=True
|
133 |
+
)
|
134 |
+
|
135 |
+
# Columna 2: Resultados Base
|
136 |
+
with results_base_col:
|
137 |
+
if baseline_button and text_input:
|
138 |
+
with st.spinner("Analizando l铆nea base..."):
|
139 |
+
doc = nlp_models[lang_code](text_input)
|
140 |
+
metrics = analyze_text_dimensions(doc)
|
141 |
+
display_results(metrics, 'student_essay')
|
142 |
+
st.session_state.baseline_metrics = metrics
|
143 |
+
|
144 |
+
# Columna 3: Texto Iteraci贸n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
with text_iter_col:
|
146 |
+
st.markdown("### Texto Iterativo")
|
147 |
+
iteration_text = st.text_area(
|
148 |
+
"Nueva versi贸n del texto:",
|
149 |
height=400,
|
150 |
key="text_area_iter",
|
151 |
+
help="Escribe la versi贸n mejorada de tu texto"
|
|
|
|
|
152 |
)
|
153 |
+
|
154 |
+
iterate_button = st.button(
|
155 |
+
"Analizar Iteraci贸n",
|
|
|
|
|
|
|
|
|
|
|
156 |
type="primary",
|
157 |
+
disabled=not iteration_text.strip() or not st.session_state.baseline_metrics,
|
158 |
+
use_container_width=True
|
159 |
+
)
|
160 |
+
|
161 |
+
# Columna 4: Resultados Iteraci贸n
|
162 |
+
with results_iter_col:
|
163 |
+
if iterate_button and iteration_text:
|
164 |
+
with st.spinner("Analizando iteraci贸n..."):
|
165 |
+
doc = nlp_models[lang_code](iteration_text)
|
166 |
+
metrics = analyze_text_dimensions(doc)
|
167 |
+
display_results(metrics, 'student_essay')
|
168 |
+
|
169 |
+
# Container separado para el gr谩fico radar
|
170 |
+
with st.container():
|
171 |
+
with st.expander("Ver Comparaci贸n Visual", expanded=False):
|
172 |
+
if 'baseline_metrics' in st.session_state and 'metrics' in locals():
|
173 |
+
display_radar_chart(
|
174 |
+
metrics_config=prepare_metrics_config(metrics),
|
175 |
+
thresholds=TEXT_TYPES['student_essay']['thresholds'],
|
176 |
+
baseline_metrics=st.session_state.baseline_metrics
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
)
|
178 |
+
|
179 |
except Exception as e:
|
180 |
logger.error(f"Error en interfaz principal: {str(e)}")
|
181 |
st.error("Ocurri贸 un error al cargar la interfaz")
|
182 |
+
|
183 |
|
184 |
###################################
|
185 |
|