AIdeaText commited on
Commit
915e40c
verified
1 Parent(s): 4d6b305

Update modules/morphosyntax/morphosyntax_interface.py

Browse files
modules/morphosyntax/morphosyntax_interface.py CHANGED
@@ -31,6 +31,20 @@ import logging
31
  logger = logging.getLogger(__name__)
32
 
33
  ###########################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def reset_morpho_state():
35
  """Resetea el estado del an谩lisis morfosint谩ctico"""
36
  if 'arc_analysis_state' in st.session_state:
@@ -76,9 +90,8 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
76
  </style>
77
  """, unsafe_allow_html=True)
78
 
79
- # Estado para subtabs
80
- if 'morpho_subtab' not in st.session_state:
81
- st.session_state.morpho_subtab = 0
82
 
83
  # Crear subtabs
84
  subtabs = st.tabs([
@@ -96,8 +109,6 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
96
  reset_morpho_state()
97
  st.rerun()
98
 
99
- # Estado para an谩lisis...
100
-
101
  # Contenedores separados para cada tipo de an谩lisis
102
  original_input_container = st.container()
103
  original_diagram_container = st.container()
@@ -119,7 +130,8 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
119
  analyze_button = st.button(
120
  "Analizar Texto Original",
121
  type="primary",
122
- key=f"analyze_original_{st.session_state.arc_analysis_state['analysis_count']}"
 
123
  )
124
 
125
  # Procesar texto original
@@ -131,7 +143,6 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
131
  nlp_models[lang_code]
132
  )
133
 
134
- # Actualizar estado
135
  st.session_state.arc_analysis_state.update({
136
  'original_text': text_input,
137
  'original_analysis': {'doc': doc, 'analysis': analysis},
@@ -145,23 +156,22 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
145
  arc_diagrams=analysis['arc_diagrams']
146
  ):
147
  display_original_analysis(
148
- original_diagram_container,
149
  st.session_state.arc_analysis_state['original_analysis'],
150
  lang_code,
151
  morpho_t
152
  )
 
153
  except Exception as e:
154
  st.error("Error al procesar texto original")
155
- logger.error(f"Error: {str(e)}")
156
 
157
  # Secci贸n de iteraci贸n
158
  if st.session_state.arc_analysis_state.get('original_analysis'):
159
  with iteration_input_container:
160
  st.markdown("---")
161
- iteration_key = f"iteration_{st.session_state.arc_analysis_state['analysis_count']}"
162
-
163
- # Usar un formulario para evitar recargas innecesarias
164
  with st.form(key="iteration_form"):
 
165
  iteration_text = st.text_area(
166
  "",
167
  value=st.session_state.arc_analysis_state['iteration_text'],
@@ -182,7 +192,6 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
182
  nlp_models[lang_code]
183
  )
184
 
185
- # Actualizar solo el an谩lisis de iteraci贸n
186
  st.session_state.arc_analysis_state.update({
187
  'iteration_text': iteration_text,
188
  'iteration_analysis': {'doc': doc_iter, 'analysis': analysis_iter}
@@ -193,6 +202,14 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
193
  text=iteration_text,
194
  arc_diagrams=analysis_iter['arc_diagrams']
195
  ):
 
 
 
 
 
 
 
 
196
  display_iteration_analysis(
197
  iteration_diagram_container,
198
  {'doc': doc_iter, 'analysis': analysis_iter},
@@ -202,14 +219,18 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
202
 
203
  except Exception as e:
204
  st.error("Error al procesar iteraci贸n")
205
- logger.error(f"Error: {str(e)}")
206
 
207
  # Otros subtabs...
 
 
 
 
 
208
 
209
  except Exception as e:
210
  st.error("Error general en la interfaz")
211
- logger.error(f"Error: {str(e)}")
212
-
213
 
214
  ############################################################################
215
 
 
31
  logger = logging.getLogger(__name__)
32
 
33
  ###########################################################################
34
+ def initialize_arc_analysis_state():
35
+ """Inicializa el estado del an谩lisis de arcos si no existe"""
36
+ if 'arc_analysis_state' not in st.session_state:
37
+ st.session_state.arc_analysis_state = {
38
+ 'original_text': '',
39
+ 'original_analysis': None,
40
+ 'iteration_text': '',
41
+ 'iteration_analysis': None,
42
+ 'analysis_count': 0
43
+ }
44
+ logger.info("Estado de an谩lisis de arcos inicializado")
45
+
46
+ ###########################################################################
47
+
48
  def reset_morpho_state():
49
  """Resetea el estado del an谩lisis morfosint谩ctico"""
50
  if 'arc_analysis_state' in st.session_state:
 
90
  </style>
91
  """, unsafe_allow_html=True)
92
 
93
+ # Inicializar estado
94
+ initialize_arc_analysis_state()
 
95
 
96
  # Crear subtabs
97
  subtabs = st.tabs([
 
109
  reset_morpho_state()
110
  st.rerun()
111
 
 
 
112
  # Contenedores separados para cada tipo de an谩lisis
113
  original_input_container = st.container()
114
  original_diagram_container = st.container()
 
130
  analyze_button = st.button(
131
  "Analizar Texto Original",
132
  type="primary",
133
+ key=f"analyze_original_{st.session_state.arc_analysis_state['analysis_count']}",
134
+ use_container_width=True
135
  )
136
 
137
  # Procesar texto original
 
143
  nlp_models[lang_code]
144
  )
145
 
 
146
  st.session_state.arc_analysis_state.update({
147
  'original_text': text_input,
148
  'original_analysis': {'doc': doc, 'analysis': analysis},
 
156
  arc_diagrams=analysis['arc_diagrams']
157
  ):
158
  display_original_analysis(
159
+ original_diagram_container,
160
  st.session_state.arc_analysis_state['original_analysis'],
161
  lang_code,
162
  morpho_t
163
  )
164
+
165
  except Exception as e:
166
  st.error("Error al procesar texto original")
167
+ logger.error(f"Error al procesar texto original: {str(e)}")
168
 
169
  # Secci贸n de iteraci贸n
170
  if st.session_state.arc_analysis_state.get('original_analysis'):
171
  with iteration_input_container:
172
  st.markdown("---")
 
 
 
173
  with st.form(key="iteration_form"):
174
+ iteration_key = f"iteration_{st.session_state.arc_analysis_state['analysis_count']}"
175
  iteration_text = st.text_area(
176
  "",
177
  value=st.session_state.arc_analysis_state['iteration_text'],
 
192
  nlp_models[lang_code]
193
  )
194
 
 
195
  st.session_state.arc_analysis_state.update({
196
  'iteration_text': iteration_text,
197
  'iteration_analysis': {'doc': doc_iter, 'analysis': analysis_iter}
 
202
  text=iteration_text,
203
  arc_diagrams=analysis_iter['arc_diagrams']
204
  ):
205
+ # Mostrar an谩lisis original y de cambios
206
+ display_original_analysis(
207
+ original_diagram_container,
208
+ st.session_state.arc_analysis_state['original_analysis'],
209
+ lang_code,
210
+ morpho_t
211
+ )
212
+
213
  display_iteration_analysis(
214
  iteration_diagram_container,
215
  {'doc': doc_iter, 'analysis': analysis_iter},
 
219
 
220
  except Exception as e:
221
  st.error("Error al procesar iteraci贸n")
222
+ logger.error(f"Error al procesar iteraci贸n: {str(e)}")
223
 
224
  # Otros subtabs...
225
+ with subtabs[1]:
226
+ st.info("An谩lisis de Categor铆as en desarrollo...")
227
+
228
+ with subtabs[2]:
229
+ st.info("An谩lisis Morfol贸gico en desarrollo...")
230
 
231
  except Exception as e:
232
  st.error("Error general en la interfaz")
233
+ logger.error(f"Error general en la interfaz: {str(e)}")
 
234
 
235
  ############################################################################
236