Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -62,136 +62,154 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
62 |
</style>
|
63 |
""", unsafe_allow_html=True)
|
64 |
|
65 |
-
# Estado
|
66 |
-
if '
|
67 |
-
st.session_state.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
)
|
94 |
-
|
95 |
-
# Contenedor para visualizaciones
|
96 |
-
diagram_container = st.container()
|
97 |
-
iteration_container = st.container()
|
98 |
-
|
99 |
-
# Procesar texto original
|
100 |
-
if analyze_button and text_input.strip():
|
101 |
-
try:
|
102 |
-
doc = nlp_models[lang_code](text_input)
|
103 |
-
analysis = perform_advanced_morphosyntactic_analysis(
|
104 |
-
text_input,
|
105 |
-
nlp_models[lang_code]
|
106 |
-
)
|
107 |
-
|
108 |
-
st.session_state.morpho_state.update({
|
109 |
-
'original_text': text_input,
|
110 |
-
'original_analysis': {'doc': doc, 'analysis': analysis},
|
111 |
-
'iteration_text': text_input,
|
112 |
-
'show_original': True,
|
113 |
-
'analysis_count': st.session_state.morpho_state['analysis_count'] + 1
|
114 |
-
})
|
115 |
-
|
116 |
-
if store_student_morphosyntax_result(
|
117 |
-
username=st.session_state.username,
|
118 |
-
text=text_input,
|
119 |
-
arc_diagrams=analysis['arc_diagrams']
|
120 |
-
):
|
121 |
-
with diagram_container:
|
122 |
-
st.subheader("An谩lisis Original")
|
123 |
-
display_morphosyntax_results(
|
124 |
-
st.session_state.morpho_state['original_analysis'],
|
125 |
-
lang_code,
|
126 |
-
morpho_t
|
127 |
-
)
|
128 |
-
except Exception as e:
|
129 |
-
st.error("Error al procesar texto original")
|
130 |
-
logger.error(f"Error: {str(e)}")
|
131 |
-
|
132 |
-
# Mostrar secci贸n de iteraci贸n si hay an谩lisis original
|
133 |
-
if st.session_state.morpho_state.get('show_original', False):
|
134 |
-
with iteration_container:
|
135 |
-
st.markdown("---")
|
136 |
-
iteration_key = f"iteration_{st.session_state.morpho_state['analysis_count']}"
|
137 |
-
iteration_text = st.text_area(
|
138 |
"",
|
139 |
-
value=st.session_state.
|
140 |
-
key=
|
141 |
height=100
|
142 |
)
|
143 |
|
144 |
col1, col2, col3 = st.columns([2,1,2])
|
145 |
with col1:
|
146 |
-
|
147 |
-
"Analizar
|
148 |
-
type="primary",
|
149 |
-
use_container_width=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
)
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
158 |
)
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
|
196 |
except Exception as e:
|
197 |
st.error("Error general en la interfaz")
|
|
|
62 |
</style>
|
63 |
""", unsafe_allow_html=True)
|
64 |
|
65 |
+
# Estado para subtabs
|
66 |
+
if 'morpho_subtab' not in st.session_state:
|
67 |
+
st.session_state.morpho_subtab = 0
|
68 |
+
|
69 |
+
# Crear subtabs
|
70 |
+
subtabs = st.tabs([
|
71 |
+
"An谩lisis de Diagramas de Arco",
|
72 |
+
"An谩lisis de Categor铆as",
|
73 |
+
"An谩lisis Morfol贸gico"
|
74 |
+
])
|
75 |
+
|
76 |
+
# Tab de Diagramas de Arco
|
77 |
+
with subtabs[0]:
|
78 |
+
# Estado para an谩lisis
|
79 |
+
if 'arc_analysis_state' not in st.session_state:
|
80 |
+
st.session_state.arc_analysis_state = {
|
81 |
+
'original_text': '',
|
82 |
+
'original_analysis': None,
|
83 |
+
'iteration_text': '',
|
84 |
+
'iteration_analysis': None,
|
85 |
+
'analysis_count': 0
|
86 |
+
}
|
87 |
+
|
88 |
+
# Contenedor para texto original
|
89 |
+
original_container = st.container()
|
90 |
+
with original_container:
|
91 |
+
text_key = f"original_text_{st.session_state.arc_analysis_state['analysis_count']}"
|
92 |
+
text_input = st.text_area(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
"",
|
94 |
+
value=st.session_state.arc_analysis_state['original_text'],
|
95 |
+
key=text_key,
|
96 |
height=100
|
97 |
)
|
98 |
|
99 |
col1, col2, col3 = st.columns([2,1,2])
|
100 |
with col1:
|
101 |
+
analyze_button = st.button(
|
102 |
+
"Analizar Texto Original",
|
103 |
+
type="primary",
|
104 |
+
use_container_width=True,
|
105 |
+
key=f"analyze_original_{st.session_state.arc_analysis_state['analysis_count']}"
|
106 |
+
)
|
107 |
+
|
108 |
+
# Contenedor para diagramas
|
109 |
+
diagrams_container = st.container()
|
110 |
+
|
111 |
+
# Procesar texto original
|
112 |
+
if analyze_button and text_input.strip():
|
113 |
+
try:
|
114 |
+
doc = nlp_models[lang_code](text_input)
|
115 |
+
analysis = perform_advanced_morphosyntactic_analysis(
|
116 |
+
text_input,
|
117 |
+
nlp_models[lang_code]
|
118 |
+
)
|
119 |
+
|
120 |
+
st.session_state.arc_analysis_state.update({
|
121 |
+
'original_text': text_input,
|
122 |
+
'original_analysis': {'doc': doc, 'analysis': analysis},
|
123 |
+
'iteration_text': text_input,
|
124 |
+
'analysis_count': st.session_state.arc_analysis_state['analysis_count'] + 1
|
125 |
+
})
|
126 |
+
|
127 |
+
if store_student_morphosyntax_result(
|
128 |
+
username=st.session_state.username,
|
129 |
+
text=text_input,
|
130 |
+
arc_diagrams=analysis['arc_diagrams']
|
131 |
+
):
|
132 |
+
with diagrams_container:
|
133 |
+
st.subheader("An谩lisis Original")
|
134 |
+
display_morphosyntax_results(
|
135 |
+
st.session_state.arc_analysis_state['original_analysis'],
|
136 |
+
lang_code,
|
137 |
+
morpho_t
|
138 |
+
)
|
139 |
+
except Exception as e:
|
140 |
+
st.error("Error al procesar texto original")
|
141 |
+
logger.error(f"Error: {str(e)}")
|
142 |
+
|
143 |
+
# Contenedor para iteraci贸n
|
144 |
+
if st.session_state.arc_analysis_state.get('original_analysis'):
|
145 |
+
iteration_container = st.container()
|
146 |
+
with iteration_container:
|
147 |
+
st.markdown("---")
|
148 |
+
iteration_key = f"iteration_{st.session_state.arc_analysis_state['analysis_count']}"
|
149 |
+
iteration_text = st.text_area(
|
150 |
+
"",
|
151 |
+
value=st.session_state.arc_analysis_state['iteration_text'],
|
152 |
+
key=iteration_key,
|
153 |
+
height=100,
|
154 |
+
on_change=lambda: None # Prevenir recarga en cambio de foco
|
155 |
)
|
156 |
|
157 |
+
col1, col2, col3 = st.columns([2,1,2])
|
158 |
+
with col1:
|
159 |
+
iterate_button = st.button(
|
160 |
+
"Analizar Cambios",
|
161 |
+
type="primary",
|
162 |
+
use_container_width=True,
|
163 |
+
key=f"iterate_{st.session_state.arc_analysis_state['analysis_count']}"
|
164 |
)
|
165 |
|
166 |
+
if iterate_button and iteration_text.strip():
|
167 |
+
try:
|
168 |
+
doc_iter = nlp_models[lang_code](iteration_text)
|
169 |
+
analysis_iter = perform_advanced_morphosyntactic_analysis(
|
170 |
+
iteration_text,
|
171 |
+
nlp_models[lang_code]
|
172 |
+
)
|
173 |
+
|
174 |
+
st.session_state.arc_analysis_state.update({
|
175 |
+
'iteration_text': iteration_text,
|
176 |
+
'iteration_analysis': {'doc': doc_iter, 'analysis': analysis_iter}
|
177 |
+
})
|
178 |
+
|
179 |
+
if store_student_morphosyntax_result(
|
180 |
+
username=st.session_state.username,
|
181 |
+
text=iteration_text,
|
182 |
+
arc_diagrams=analysis_iter['arc_diagrams']
|
183 |
+
):
|
184 |
+
with diagrams_container:
|
185 |
+
# Mostrar original
|
186 |
+
st.subheader("An谩lisis Original")
|
187 |
+
display_morphosyntax_results(
|
188 |
+
st.session_state.arc_analysis_state['original_analysis'],
|
189 |
+
lang_code,
|
190 |
+
morpho_t
|
191 |
+
)
|
192 |
+
|
193 |
+
st.markdown("---")
|
194 |
+
|
195 |
+
# Mostrar iteraci贸n
|
196 |
+
st.subheader("An谩lisis de Cambios")
|
197 |
+
display_morphosyntax_results(
|
198 |
+
{'doc': doc_iter, 'analysis': analysis_iter},
|
199 |
+
lang_code,
|
200 |
+
morpho_t
|
201 |
+
)
|
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 aqu铆...
|
208 |
+
with subtabs[1]:
|
209 |
+
st.info("An谩lisis de Categor铆as en desarrollo...")
|
210 |
+
|
211 |
+
with subtabs[2]:
|
212 |
+
st.info("An谩lisis Morfol贸gico en desarrollo...")
|
213 |
|
214 |
except Exception as e:
|
215 |
st.error("Error general en la interfaz")
|