Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -109,13 +109,18 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
109 |
padding: 0.5rem;
|
110 |
margin: 0.5rem 0;
|
111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
</style>
|
113 |
""", unsafe_allow_html=True)
|
114 |
|
115 |
-
#
|
116 |
st.session_state.tab_states['morpho_active'] = True
|
117 |
st.session_state.selected_tab = 1
|
118 |
-
initialize_arc_analysis_state()
|
119 |
|
120 |
# Crear subtabs
|
121 |
subtabs = st.tabs([
|
@@ -130,155 +135,116 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
130 |
col1, col2, col3 = st.columns([2,1,2])
|
131 |
with col1:
|
132 |
if st.button("Nuevo An谩lisis", type="secondary", use_container_width=True):
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
134 |
st.rerun()
|
135 |
|
136 |
-
#
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
# Secci贸n de an谩lisis original
|
143 |
-
with original_input_container:
|
144 |
-
text_key = f"original_text_{st.session_state.arc_analysis_state['analysis_count']}"
|
145 |
text_input = st.text_area(
|
146 |
"",
|
147 |
-
value=st.session_state.arc_analysis_state
|
148 |
-
key=
|
149 |
height=100
|
150 |
)
|
151 |
|
|
|
152 |
col1, col2, col3 = st.columns([2,1,2])
|
153 |
with col1:
|
154 |
analyze_button = st.button(
|
155 |
-
"Analizar Texto
|
156 |
type="primary",
|
157 |
-
key=f"analyze_original_{st.session_state.arc_analysis_state['analysis_count']}",
|
158 |
use_container_width=True
|
159 |
)
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
st.session_state.arc_analysis_state.update({
|
171 |
-
'original_text': text_input,
|
172 |
-
'original_analysis': {'doc': doc, 'analysis': analysis},
|
173 |
-
'iteration_text': text_input,
|
174 |
-
'analysis_count': st.session_state.arc_analysis_state['analysis_count'] + 1
|
175 |
-
})
|
176 |
-
|
177 |
-
if store_student_morphosyntax_result(
|
178 |
-
username=st.session_state.username,
|
179 |
-
text=text_input,
|
180 |
-
arc_diagrams=analysis['arc_diagrams']
|
181 |
-
):
|
182 |
-
display_original_analysis(
|
183 |
-
original_diagram_container,
|
184 |
-
st.session_state.arc_analysis_state['original_analysis'],
|
185 |
-
lang_code,
|
186 |
-
morpho_t
|
187 |
)
|
188 |
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
if st.session_state.arc_analysis_state.get('original_analysis'):
|
195 |
-
with iteration_input_container:
|
196 |
-
st.markdown("---")
|
197 |
-
|
198 |
-
# Formulario de iteraci贸n
|
199 |
-
with st.form(key="iteration_form"):
|
200 |
-
iteration_text = st.text_area(
|
201 |
-
"",
|
202 |
-
value=st.session_state.arc_analysis_state.get('iteration_text', ''),
|
203 |
-
key=f"iteration_{st.session_state.arc_analysis_state['analysis_count']}",
|
204 |
-
height=100
|
205 |
)
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
231 |
)
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
)
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
)
|
260 |
-
|
261 |
-
with col2:
|
262 |
-
display_iteration_analysis(
|
263 |
-
iteration_diagram_container,
|
264 |
-
{'doc': doc_iter, 'analysis': analysis_iter},
|
265 |
-
lang_code,
|
266 |
-
morpho_t
|
267 |
-
)
|
268 |
-
|
269 |
-
except Exception as e:
|
270 |
-
st.error("Error al procesar iteraci贸n")
|
271 |
-
logger.error(f"Error al procesar iteraci贸n: {str(e)}")
|
272 |
-
|
273 |
-
# Otros subtabs...
|
274 |
with subtabs[1]:
|
275 |
st.info("An谩lisis de Categor铆as en desarrollo...")
|
276 |
-
|
277 |
with subtabs[2]:
|
278 |
st.info("An谩lisis Morfol贸gico en desarrollo...")
|
279 |
|
280 |
except Exception as e:
|
281 |
-
st.error("Error
|
282 |
logger.error(f"Error general en la interfaz: {str(e)}")
|
283 |
|
284 |
############################################################################
|
|
|
109 |
padding: 0.5rem;
|
110 |
margin: 0.5rem 0;
|
111 |
}
|
112 |
+
.divider {
|
113 |
+
height: 3px;
|
114 |
+
border: none;
|
115 |
+
background-color: #333;
|
116 |
+
margin: 2rem 0;
|
117 |
+
}
|
118 |
</style>
|
119 |
""", unsafe_allow_html=True)
|
120 |
|
121 |
+
# Asegurar que el tab morfosint谩ctico permanece activo
|
122 |
st.session_state.tab_states['morpho_active'] = True
|
123 |
st.session_state.selected_tab = 1
|
|
|
124 |
|
125 |
# Crear subtabs
|
126 |
subtabs = st.tabs([
|
|
|
135 |
col1, col2, col3 = st.columns([2,1,2])
|
136 |
with col1:
|
137 |
if st.button("Nuevo An谩lisis", type="secondary", use_container_width=True):
|
138 |
+
st.session_state.arc_analysis_state = {
|
139 |
+
'base_id': None,
|
140 |
+
'original_text': '',
|
141 |
+
'iteration_text': '',
|
142 |
+
'analysis_count': 0
|
143 |
+
}
|
144 |
st.rerun()
|
145 |
|
146 |
+
# Container principal para an谩lisis
|
147 |
+
analysis_container = st.container()
|
148 |
+
|
149 |
+
with analysis_container:
|
150 |
+
# Entrada de texto original
|
|
|
|
|
|
|
|
|
151 |
text_input = st.text_area(
|
152 |
"",
|
153 |
+
value=st.session_state.arc_analysis_state.get('original_text', ''),
|
154 |
+
key=f"original_text_{st.session_state.arc_analysis_state['analysis_count']}",
|
155 |
height=100
|
156 |
)
|
157 |
|
158 |
+
# Bot贸n de an谩lisis
|
159 |
col1, col2, col3 = st.columns([2,1,2])
|
160 |
with col1:
|
161 |
analyze_button = st.button(
|
162 |
+
"Analizar Texto",
|
163 |
type="primary",
|
|
|
164 |
use_container_width=True
|
165 |
)
|
166 |
|
167 |
+
# Procesar texto original
|
168 |
+
if analyze_button and text_input.strip():
|
169 |
+
try:
|
170 |
+
# Realizar an谩lisis base
|
171 |
+
doc = nlp_models[lang_code](text_input)
|
172 |
+
analysis = perform_advanced_morphosyntactic_analysis(
|
173 |
+
text_input,
|
174 |
+
nlp_models[lang_code]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
)
|
176 |
|
177 |
+
# Guardar an谩lisis base y obtener ID
|
178 |
+
base_id = store_student_morphosyntax_base(
|
179 |
+
st.session_state.username,
|
180 |
+
text_input,
|
181 |
+
analysis['arc_diagrams']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
)
|
183 |
+
|
184 |
+
if base_id:
|
185 |
+
# Actualizar estado
|
186 |
+
st.session_state.arc_analysis_state.update({
|
187 |
+
'base_id': base_id,
|
188 |
+
'original_text': text_input,
|
189 |
+
'analysis_count': st.session_state.arc_analysis_state['analysis_count'] + 1
|
190 |
+
})
|
191 |
+
|
192 |
+
# Mostrar diagrama base
|
193 |
+
display_arc_diagram(doc, analysis)
|
194 |
+
|
195 |
+
# L铆nea divisora
|
196 |
+
st.markdown('<hr class="divider">', unsafe_allow_html=True)
|
197 |
+
|
198 |
+
# 脕rea de iteraci贸n
|
199 |
+
with st.form("iteration_form"):
|
200 |
+
iteration_text = st.text_area(
|
201 |
+
"",
|
202 |
+
value=text_input,
|
203 |
+
height=100
|
204 |
+
)
|
205 |
+
|
206 |
+
col1, col2, col3 = st.columns([2,1,2])
|
207 |
+
with col1:
|
208 |
+
submitted = st.form_submit_button(
|
209 |
+
"Analizar Cambios",
|
210 |
+
type="primary",
|
211 |
+
use_container_width=True
|
212 |
)
|
213 |
+
|
214 |
+
# Procesar iteraci贸n
|
215 |
+
if submitted and iteration_text.strip():
|
216 |
+
doc_iter = nlp_models[lang_code](iteration_text)
|
217 |
+
analysis_iter = perform_advanced_morphosyntactic_analysis(
|
218 |
+
iteration_text,
|
219 |
+
nlp_models[lang_code]
|
220 |
+
)
|
221 |
+
|
222 |
+
# Guardar iteraci贸n
|
223 |
+
iteration_id = store_student_morphosyntax_iteration(
|
224 |
+
st.session_state.username,
|
225 |
+
base_id,
|
226 |
+
text_input,
|
227 |
+
iteration_text,
|
228 |
+
analysis_iter['arc_diagrams']
|
229 |
+
)
|
230 |
+
|
231 |
+
if iteration_id:
|
232 |
+
# Mostrar diagrama de iteraci贸n
|
233 |
+
display_arc_diagram(doc_iter, analysis_iter)
|
234 |
+
|
235 |
+
except Exception as e:
|
236 |
+
st.error("Error procesando an谩lisis")
|
237 |
+
logger.error(f"Error: {str(e)}")
|
238 |
+
|
239 |
+
# Otros subtabs mantienen su implementaci贸n actual...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
with subtabs[1]:
|
241 |
st.info("An谩lisis de Categor铆as en desarrollo...")
|
242 |
+
|
243 |
with subtabs[2]:
|
244 |
st.info("An谩lisis Morfol贸gico en desarrollo...")
|
245 |
|
246 |
except Exception as e:
|
247 |
+
st.error("Error en la interfaz")
|
248 |
logger.error(f"Error general en la interfaz: {str(e)}")
|
249 |
|
250 |
############################################################################
|