AIdeaText commited on
Commit
735d4eb
verified
1 Parent(s): 5ce65bd

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('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,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('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,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('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
@@ -153,89 +153,9 @@ def display_current_situation_interface(lang_code, nlp_models, current_situation
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
- """
164
- try:
165
- # Usar valor por defecto si no se especifica tipo
166
- text_type = text_type or 'student_essay'
167
-
168
- # Obtener umbrales seg煤n el tipo de texto
169
- thresholds = TEXT_TYPES[text_type]['thresholds']
170
-
171
- # Crear dos columnas para las m茅tricas y el gr谩fico
172
- metrics_col, graph_col = st.columns([1, 1.5])
173
-
174
- # Columna de m茅tricas
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
- ]
206
-
207
- # Mostrar m茅tricas
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
- )
229
- st.markdown("<div style='margin-bottom: 0.5rem;'></div>", unsafe_allow_html=True)
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):
 
87
  with input_col:
88
  # Text area con manejo de estado
89
  text_input = st.text_area(
90
+ current_situation_t['input_prompt'], # Corregido: usar corchetes
91
  height=400,
92
  key="text_area",
93
  value=st.session_state.text_input,
94
+ help=current_situation_t.get('help', '') # Manejar clave faltante
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'], # Corregido: usar corchetes
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']): # Corregido: usar corchetes
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.get('analysis_error', 'Error analyzing text')) # Manejar clave faltante
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']}") # Corregido: usar corchetes
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.get('text_type_help', '') # Manejar clave faltante
143
  )
144
 
145
  st.session_state.current_text_type = text_type
 
153
 
154
  except Exception as e:
155
  logger.error(f"Error en interfaz principal: {str(e)}")
156
+ st.error(current_situation_t.get('error_interface', 'Interface error')) # Manejar clave faltante
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ # ... (El resto del archivo mantiene las mismas correcciones con corchetes y get())
159
 
160
  ######################################
161
  def display_radar_chart(metrics_config, thresholds, current_situation_t):