AIdeaText commited on
Commit
0bd5403
verified
1 Parent(s): 9c06153

Update modules/studentact/current_situation_interface.py

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