Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
#modules/morphosyntax/morphosyntax_interface.py
|
2 |
|
|
|
3 |
import streamlit as st
|
4 |
from streamlit_float import *
|
5 |
from streamlit_antd_components import *
|
@@ -11,6 +12,7 @@ import pandas as pd
|
|
11 |
import base64
|
12 |
import re
|
13 |
|
|
|
14 |
from .morphosyntax_process import (
|
15 |
process_morphosyntactic_input,
|
16 |
format_analysis_results,
|
@@ -29,17 +31,29 @@ import logging
|
|
29 |
logger = logging.getLogger(__name__)
|
30 |
|
31 |
###########################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
############################################################################
|
45 |
|
@@ -75,19 +89,23 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
75 |
|
76 |
# Tab de Diagramas de Arco
|
77 |
with subtabs[0]:
|
78 |
-
#
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
91 |
text_key = f"original_text_{st.session_state.arc_analysis_state['analysis_count']}"
|
92 |
text_input = st.text_area(
|
93 |
"",
|
@@ -101,13 +119,9 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
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:
|
@@ -117,6 +131,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
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},
|
@@ -129,38 +144,34 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
129 |
text=text_input,
|
130 |
arc_diagrams=analysis['arc_diagrams']
|
131 |
):
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
)
|
139 |
except Exception as e:
|
140 |
st.error("Error al procesar texto original")
|
141 |
logger.error(f"Error: {str(e)}")
|
142 |
|
143 |
-
#
|
144 |
if st.session_state.arc_analysis_state.get('original_analysis'):
|
145 |
-
|
146 |
-
with iteration_container:
|
147 |
st.markdown("---")
|
148 |
iteration_key = f"iteration_{st.session_state.arc_analysis_state['analysis_count']}"
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
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():
|
@@ -171,6 +182,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
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}
|
@@ -181,40 +193,24 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
181 |
text=iteration_text,
|
182 |
arc_diagrams=analysis_iter['arc_diagrams']
|
183 |
):
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
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
|
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")
|
216 |
logger.error(f"Error: {str(e)}")
|
217 |
|
|
|
218 |
############################################################################
|
219 |
|
220 |
def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
|
1 |
#modules/morphosyntax/morphosyntax_interface.py
|
2 |
|
3 |
+
#Importaciones generales
|
4 |
import streamlit as st
|
5 |
from streamlit_float import *
|
6 |
from streamlit_antd_components import *
|
|
|
12 |
import base64
|
13 |
import re
|
14 |
|
15 |
+
#Importaciones locales
|
16 |
from .morphosyntax_process import (
|
17 |
process_morphosyntactic_input,
|
18 |
format_analysis_results,
|
|
|
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:
|
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 |
+
############################################################################
|
45 |
|
46 |
+
def display_original_analysis(container, analysis, lang_code, morpho_t):
|
47 |
+
"""Muestra el an谩lisis original en el contenedor especificado"""
|
48 |
+
with container:
|
49 |
+
st.subheader("An谩lisis Original")
|
50 |
+
display_morphosyntax_results(analysis, lang_code, morpho_t)
|
51 |
+
|
52 |
+
def display_iteration_analysis(container, analysis, lang_code, morpho_t):
|
53 |
+
"""Muestra el an谩lisis de cambios en el contenedor especificado"""
|
54 |
+
with container:
|
55 |
+
st.subheader("An谩lisis de Cambios")
|
56 |
+
display_morphosyntax_results(analysis, lang_code, morpho_t)
|
57 |
|
58 |
############################################################################
|
59 |
|
|
|
89 |
|
90 |
# Tab de Diagramas de Arco
|
91 |
with subtabs[0]:
|
92 |
+
# Bot贸n de reset
|
93 |
+
col1, col2, col3 = st.columns([2,1,2])
|
94 |
+
with col1:
|
95 |
+
if st.button("Nuevo An谩lisis", type="secondary", use_container_width=True):
|
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()
|
104 |
+
iteration_input_container = st.container()
|
105 |
+
iteration_diagram_container = st.container()
|
106 |
+
|
107 |
+
# Secci贸n de an谩lisis original
|
108 |
+
with original_input_container:
|
109 |
text_key = f"original_text_{st.session_state.arc_analysis_state['analysis_count']}"
|
110 |
text_input = st.text_area(
|
111 |
"",
|
|
|
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
|
126 |
if analyze_button and text_input.strip():
|
127 |
try:
|
|
|
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},
|
|
|
144 |
text=text_input,
|
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'],
|
168 |
+
key=iteration_key,
|
169 |
+
height=100
|
170 |
+
)
|
171 |
+
iterate_button = st.form_submit_button(
|
|
|
172 |
"Analizar Cambios",
|
173 |
+
type="primary",
|
174 |
+
use_container_width=True
|
|
|
175 |
)
|
176 |
|
177 |
if iterate_button and iteration_text.strip():
|
|
|
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 |
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},
|
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...
|
|
|
|
|
|
|
|
|
|
|
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 |
|
216 |
def display_morphosyntax_results(result, lang_code, morpho_t):
|