Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -5,8 +5,7 @@ import re
|
|
5 |
import logging
|
6 |
from spacy import displacy
|
7 |
|
8 |
-
#
|
9 |
-
# y los m茅todos store_student_morphosyntax_base/iteration existen.
|
10 |
from ..morphosyntax.morphosyntax_process import perform_advanced_morphosyntactic_analysis
|
11 |
from ..database.morphosyntax_iterative_mongo_db import (
|
12 |
store_student_morphosyntax_base,
|
@@ -15,12 +14,9 @@ from ..database.morphosyntax_iterative_mongo_db import (
|
|
15 |
|
16 |
logger = logging.getLogger(__name__)
|
17 |
|
18 |
-
|
19 |
###########################################################################
|
20 |
def initialize_arc_analysis_state():
|
21 |
-
"""
|
22 |
-
Inicializa el estado de an谩lisis de arcos (base e iteraciones) si no existe.
|
23 |
-
"""
|
24 |
if "arc_analysis_state" not in st.session_state:
|
25 |
st.session_state.arc_analysis_state = {
|
26 |
"base_id": None,
|
@@ -33,9 +29,7 @@ def initialize_arc_analysis_state():
|
|
33 |
|
34 |
###########################################################################
|
35 |
def reset_arc_analysis_state():
|
36 |
-
"""
|
37 |
-
Resetea completamente el estado de an谩lisis de arcos.
|
38 |
-
"""
|
39 |
st.session_state.arc_analysis_state = {
|
40 |
"base_id": None,
|
41 |
"base_text": "",
|
@@ -49,8 +43,7 @@ def reset_arc_analysis_state():
|
|
49 |
def display_arc_diagram(doc):
|
50 |
"""
|
51 |
Genera y retorna el HTML del diagrama de arco para un `Doc` de spaCy.
|
52 |
-
No imprime directamente
|
53 |
-
usar con `st.write(..., unsafe_allow_html=True)`.
|
54 |
"""
|
55 |
try:
|
56 |
diagram_html = ""
|
@@ -126,7 +119,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
126 |
|
127 |
# Bot贸n para iniciar nuevo an谩lisis
|
128 |
if st.button("Nuevo An谩lisis", key="btn_reset_base"):
|
129 |
-
# Si requieres recargar la app por completo:
|
130 |
# st.experimental_rerun()
|
131 |
reset_arc_analysis_state()
|
132 |
|
@@ -146,9 +139,8 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
146 |
try:
|
147 |
# Procesar con spaCy
|
148 |
doc = nlp_models[lang_code](arc_state["base_text"])
|
149 |
-
|
150 |
-
|
151 |
-
arc_state["base_diagram"] = arc_html
|
152 |
|
153 |
# Guardar en Mongo
|
154 |
analysis = perform_advanced_morphosyntactic_analysis(
|
@@ -178,27 +170,28 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
178 |
with tabs[1]:
|
179 |
st.subheader("An谩lisis de Cambios / Iteraciones")
|
180 |
|
181 |
-
# Verificar que exista texto base
|
182 |
if not arc_state["base_id"]:
|
183 |
st.info("Primero analiza un texto base en la pesta帽a anterior.")
|
184 |
return
|
185 |
|
186 |
-
# Mostrar
|
187 |
-
st.
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
)
|
193 |
|
194 |
-
# Caja de texto para la iteraci贸n
|
|
|
|
|
195 |
arc_state["iteration_text"] = st.text_area(
|
196 |
-
"
|
197 |
value=arc_state["iteration_text"],
|
198 |
height=150
|
199 |
)
|
200 |
|
201 |
-
# Bot贸n analizar iteraci贸n
|
202 |
if st.button("Analizar Cambios", key="btn_analyze_iteration"):
|
203 |
if not arc_state["iteration_text"].strip():
|
204 |
st.warning("Ingrese texto de iteraci贸n.")
|
@@ -228,17 +221,8 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
228 |
st.error("Error procesando iteraci贸n")
|
229 |
logger.error(f"Error en iteraci贸n: {str(exc)}")
|
230 |
|
231 |
-
#
|
232 |
-
if arc_state["
|
233 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
234 |
-
st.markdown("
|
235 |
-
|
236 |
-
# Diagrama base
|
237 |
-
st.markdown("**Diagrama Base**")
|
238 |
-
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
239 |
-
|
240 |
-
st.markdown("---")
|
241 |
-
|
242 |
-
# Diagrama iterado
|
243 |
-
st.markdown("**Diagrama Iterado**")
|
244 |
st.write(arc_state["iteration_diagram"], unsafe_allow_html=True)
|
|
|
5 |
import logging
|
6 |
from spacy import displacy
|
7 |
|
8 |
+
# Funciones de an谩lisis y DB que ya tienes en tus m贸dulos
|
|
|
9 |
from ..morphosyntax.morphosyntax_process import perform_advanced_morphosyntactic_analysis
|
10 |
from ..database.morphosyntax_iterative_mongo_db import (
|
11 |
store_student_morphosyntax_base,
|
|
|
14 |
|
15 |
logger = logging.getLogger(__name__)
|
16 |
|
|
|
17 |
###########################################################################
|
18 |
def initialize_arc_analysis_state():
|
19 |
+
"""Inicializa el estado de an谩lisis de arcos (base e iteraciones) si no existe."""
|
|
|
|
|
20 |
if "arc_analysis_state" not in st.session_state:
|
21 |
st.session_state.arc_analysis_state = {
|
22 |
"base_id": None,
|
|
|
29 |
|
30 |
###########################################################################
|
31 |
def reset_arc_analysis_state():
|
32 |
+
"""Resetea completamente el estado de an谩lisis de arcos."""
|
|
|
|
|
33 |
st.session_state.arc_analysis_state = {
|
34 |
"base_id": None,
|
35 |
"base_text": "",
|
|
|
43 |
def display_arc_diagram(doc):
|
44 |
"""
|
45 |
Genera y retorna el HTML del diagrama de arco para un `Doc` de spaCy.
|
46 |
+
No imprime directamente; retorna el HTML para usar con `st.write(...)`.
|
|
|
47 |
"""
|
48 |
try:
|
49 |
diagram_html = ""
|
|
|
119 |
|
120 |
# Bot贸n para iniciar nuevo an谩lisis
|
121 |
if st.button("Nuevo An谩lisis", key="btn_reset_base"):
|
122 |
+
# Si requieres recargar la app por completo, podr铆as descomentar:
|
123 |
# st.experimental_rerun()
|
124 |
reset_arc_analysis_state()
|
125 |
|
|
|
139 |
try:
|
140 |
# Procesar con spaCy
|
141 |
doc = nlp_models[lang_code](arc_state["base_text"])
|
142 |
+
base_arc_html = display_arc_diagram(doc)
|
143 |
+
arc_state["base_diagram"] = base_arc_html
|
|
|
144 |
|
145 |
# Guardar en Mongo
|
146 |
analysis = perform_advanced_morphosyntactic_analysis(
|
|
|
170 |
with tabs[1]:
|
171 |
st.subheader("An谩lisis de Cambios / Iteraciones")
|
172 |
|
173 |
+
# Verificar que exista un texto base
|
174 |
if not arc_state["base_id"]:
|
175 |
st.info("Primero analiza un texto base en la pesta帽a anterior.")
|
176 |
return
|
177 |
|
178 |
+
# --- 1) Mostrar SIEMPRE el diagrama base arriba ---
|
179 |
+
st.markdown("#### Diagrama de Arco (Texto Base)")
|
180 |
+
if arc_state["base_diagram"]:
|
181 |
+
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
182 |
+
else:
|
183 |
+
st.info("No hay diagrama base disponible.")
|
|
|
184 |
|
185 |
+
# --- 2) Caja de texto para la iteraci贸n ---
|
186 |
+
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
187 |
+
st.subheader("Texto de Iteraci贸n")
|
188 |
arc_state["iteration_text"] = st.text_area(
|
189 |
+
"Ingrese su nueva versi贸n / iteraci贸n",
|
190 |
value=arc_state["iteration_text"],
|
191 |
height=150
|
192 |
)
|
193 |
|
194 |
+
# Bot贸n para analizar iteraci贸n
|
195 |
if st.button("Analizar Cambios", key="btn_analyze_iteration"):
|
196 |
if not arc_state["iteration_text"].strip():
|
197 |
st.warning("Ingrese texto de iteraci贸n.")
|
|
|
221 |
st.error("Error procesando iteraci贸n")
|
222 |
logger.error(f"Error en iteraci贸n: {str(exc)}")
|
223 |
|
224 |
+
# --- 3) Mostrar diagrama de iteraci贸n debajo ---
|
225 |
+
if arc_state["iteration_diagram"]:
|
226 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
227 |
+
st.markdown("#### Diagrama de Arco (Iteraci贸n)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
st.write(arc_state["iteration_diagram"], unsafe_allow_html=True)
|