AIdeaText commited on
Commit
ce4ed7b
·
verified ·
1 Parent(s): a86a22b

Update modules/studentact/current_situation_interface.py

Browse files
modules/studentact/current_situation_interface.py CHANGED
@@ -87,11 +87,11 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
87
  with input_col:
88
  # Text area con manejo de estado
89
  text_input = st.text_area(
90
- current_situation_t.get('input_prompt', "Escribe o pega tu texto aquí:"),
91
  height=400,
92
  key="text_area",
93
  value=st.session_state.text_input,
94
- help="Este texto será analizado para darte recomendaciones personalizadas"
95
  )
96
 
97
  # Función para manejar cambios de texto
@@ -100,13 +100,13 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
100
  st.session_state.show_results = False
101
 
102
  if st.button(
103
- current_situation_t.get('analyze_button', "Analizar mi escritura"),
104
  type="primary",
105
  disabled=not text_input.strip(),
106
  use_container_width=True,
107
  ):
108
  try:
109
- with st.spinner(current_situation_t.get('processing', "Analizando...")):
110
  doc = nlp_models[lang_code](text_input)
111
  metrics = analyze_text_dimensions(doc)
112
 
@@ -126,20 +126,20 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
126
 
127
  except Exception as e:
128
  logger.error(f"Error en análisis: {str(e)}")
129
- st.error(current_situation_t.get('analysis_error', "Error al analizar el texto"))
130
 
131
  # Mostrar resultados en la columna derecha
132
  with results_col:
133
  if st.session_state.show_results and st.session_state.current_metrics is not None:
134
  # Primero los radio buttons para tipo de texto
135
- st.markdown("### Tipo de texto")
136
  text_type = st.radio(
137
  "",
138
  options=list(TEXT_TYPES.keys()),
139
  format_func=lambda x: TEXT_TYPES[x]['name'],
140
  horizontal=True,
141
  key="text_type_radio",
142
- help="Selecciona el tipo de texto para ajustar los criterios de evaluación"
143
  )
144
 
145
  st.session_state.current_text_type = text_type
@@ -147,16 +147,17 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
147
  # Luego mostrar los resultados
148
  display_results(
149
  metrics=st.session_state.current_metrics,
150
- text_type=text_type
 
151
  )
152
 
153
  except Exception as e:
154
  logger.error(f"Error en interfaz principal: {str(e)}")
155
- st.error("Ocurrió un error al cargar la interfaz")
156
 
157
- ###################################3333
158
 
159
- def display_results(metrics, text_type=None):
160
  """
161
  Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
162
  """
@@ -174,31 +175,31 @@ def display_results(metrics, text_type=None):
174
  with metrics_col:
175
  metrics_config = [
176
  {
177
- 'label': "Vocabulario",
178
  'key': 'vocabulary',
179
  'value': metrics['vocabulary']['normalized_score'],
180
- 'help': "Riqueza y variedad del vocabulario",
181
  'thresholds': thresholds['vocabulary']
182
  },
183
  {
184
- 'label': "Estructura",
185
  'key': 'structure',
186
  'value': metrics['structure']['normalized_score'],
187
- 'help': "Organización y complejidad de oraciones",
188
  'thresholds': thresholds['structure']
189
  },
190
  {
191
- 'label': "Cohesión",
192
  'key': 'cohesion',
193
  'value': metrics['cohesion']['normalized_score'],
194
- 'help': "Conexión y fluidez entre ideas",
195
  'thresholds': thresholds['cohesion']
196
  },
197
  {
198
- 'label': "Claridad",
199
  'key': 'clarity',
200
  'value': metrics['clarity']['normalized_score'],
201
- 'help': "Facilidad de comprensión del texto",
202
  'thresholds': thresholds['clarity']
203
  }
204
  ]
@@ -207,19 +208,21 @@ def display_results(metrics, text_type=None):
207
  for metric in metrics_config:
208
  value = metric['value']
209
  if value < metric['thresholds']['min']:
210
- status = "⚠️ Por mejorar"
211
  color = "inverse"
212
  elif value < metric['thresholds']['target']:
213
- status = "📈 Aceptable"
214
  color = "off"
215
  else:
216
- status = "✅ Óptimo"
217
  color = "normal"
218
 
 
 
219
  st.metric(
220
  metric['label'],
221
  f"{value:.2f}",
222
- f"{status} (Meta: {metric['thresholds']['target']:.2f})",
223
  delta_color=color,
224
  help=metric['help']
225
  )
@@ -227,15 +230,15 @@ def display_results(metrics, text_type=None):
227
 
228
  # Gráfico radar en la columna derecha
229
  with graph_col:
230
- display_radar_chart(metrics_config, thresholds)
231
 
232
  except Exception as e:
233
  logger.error(f"Error mostrando resultados: {str(e)}")
234
- st.error("Error al mostrar los resultados")
235
 
236
 
237
  ######################################
238
- def display_radar_chart(metrics_config, thresholds):
239
  """
240
  Muestra el gráfico radar con los resultados.
241
  """
@@ -278,7 +281,7 @@ def display_radar_chart(metrics_config, thresholds):
278
  # Ajustar leyenda
279
  ax.legend(
280
  loc='upper right',
281
- bbox_to_anchor=(1.3, 1.1), # Cambiado de (0.1, 0.1) a (1.3, 1.1)
282
  fontsize=10,
283
  frameon=True,
284
  facecolor='white',
@@ -292,5 +295,5 @@ def display_radar_chart(metrics_config, thresholds):
292
 
293
  except Exception as e:
294
  logger.error(f"Error mostrando gráfico radar: {str(e)}")
295
- st.error("Error al mostrar el gráfico")
296
  #######################################
 
87
  with input_col:
88
  # Text area con manejo de estado
89
  text_input = st.text_area(
90
+ current_situation_t['input_prompt'],
91
  height=400,
92
  key="text_area",
93
  value=st.session_state.text_input,
94
+ help=current_situation_t['help']
95
  )
96
 
97
  # Función para manejar cambios de texto
 
100
  st.session_state.show_results = False
101
 
102
  if st.button(
103
+ current_situation_t['analyze_button'],
104
  type="primary",
105
  disabled=not text_input.strip(),
106
  use_container_width=True,
107
  ):
108
  try:
109
+ with st.spinner(current_situation_t['processing']):
110
  doc = nlp_models[lang_code](text_input)
111
  metrics = analyze_text_dimensions(doc)
112
 
 
126
 
127
  except Exception as e:
128
  logger.error(f"Error en análisis: {str(e)}")
129
+ st.error(current_situation_t['analysis_error'])
130
 
131
  # Mostrar resultados en la columna derecha
132
  with results_col:
133
  if st.session_state.show_results and st.session_state.current_metrics is not None:
134
  # Primero los radio buttons para tipo de texto
135
+ st.markdown(f"### {current_situation_t['text_type_header']}")
136
  text_type = st.radio(
137
  "",
138
  options=list(TEXT_TYPES.keys()),
139
  format_func=lambda x: TEXT_TYPES[x]['name'],
140
  horizontal=True,
141
  key="text_type_radio",
142
+ help=current_situation_t['text_type_help']
143
  )
144
 
145
  st.session_state.current_text_type = text_type
 
147
  # Luego mostrar los resultados
148
  display_results(
149
  metrics=st.session_state.current_metrics,
150
+ text_type=text_type,
151
+ current_situation_t=current_situation_t
152
  )
153
 
154
  except Exception as e:
155
  logger.error(f"Error en interfaz principal: {str(e)}")
156
+ st.error(current_situation_t['error_interface'])
157
 
158
+ ###################################
159
 
160
+ def display_results(metrics, text_type=None, current_situation_t=None):
161
  """
162
  Muestra los resultados del análisis: métricas verticalmente y gráfico radar.
163
  """
 
175
  with metrics_col:
176
  metrics_config = [
177
  {
178
+ 'label': current_situation_t['vocabulary_label'],
179
  'key': 'vocabulary',
180
  'value': metrics['vocabulary']['normalized_score'],
181
+ 'help': current_situation_t['vocabulary_help'],
182
  'thresholds': thresholds['vocabulary']
183
  },
184
  {
185
+ 'label': current_situation_t['structure_label'],
186
  'key': 'structure',
187
  'value': metrics['structure']['normalized_score'],
188
+ 'help': current_situation_t['structure_help'],
189
  'thresholds': thresholds['structure']
190
  },
191
  {
192
+ 'label': current_situation_t['cohesion_label'],
193
  'key': 'cohesion',
194
  'value': metrics['cohesion']['normalized_score'],
195
+ 'help': current_situation_t['cohesion_help'],
196
  'thresholds': thresholds['cohesion']
197
  },
198
  {
199
+ 'label': current_situation_t['clarity_label'],
200
  'key': 'clarity',
201
  'value': metrics['clarity']['normalized_score'],
202
+ 'help': current_situation_t['clarity_help'],
203
  'thresholds': thresholds['clarity']
204
  }
205
  ]
 
208
  for metric in metrics_config:
209
  value = metric['value']
210
  if value < metric['thresholds']['min']:
211
+ status = current_situation_t['metric_improvement']
212
  color = "inverse"
213
  elif value < metric['thresholds']['target']:
214
+ status = current_situation_t['metric_acceptable']
215
  color = "off"
216
  else:
217
+ status = current_situation_t['metric_optimal']
218
  color = "normal"
219
 
220
+ target_text = current_situation_t['metric_target'].format(metric['thresholds']['target'])
221
+
222
  st.metric(
223
  metric['label'],
224
  f"{value:.2f}",
225
+ f"{status} ({target_text})",
226
  delta_color=color,
227
  help=metric['help']
228
  )
 
230
 
231
  # Gráfico radar en la columna derecha
232
  with graph_col:
233
+ display_radar_chart(metrics_config, thresholds, current_situation_t)
234
 
235
  except Exception as e:
236
  logger.error(f"Error mostrando resultados: {str(e)}")
237
+ st.error(current_situation_t['error_results'])
238
 
239
 
240
  ######################################
241
+ def display_radar_chart(metrics_config, thresholds, current_situation_t):
242
  """
243
  Muestra el gráfico radar con los resultados.
244
  """
 
281
  # Ajustar leyenda
282
  ax.legend(
283
  loc='upper right',
284
+ bbox_to_anchor=(1.3, 1.1),
285
  fontsize=10,
286
  frameon=True,
287
  facecolor='white',
 
295
 
296
  except Exception as e:
297
  logger.error(f"Error mostrando gráfico radar: {str(e)}")
298
+ st.error(current_situation_t['error_chart'])
299
  #######################################