Spaces:
Sleeping
Sleeping
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -5,7 +5,6 @@ import re
|
|
| 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,
|
|
@@ -69,7 +68,6 @@ def display_arc_diagram(doc):
|
|
| 69 |
lambda m: f'<g transform="translate({m.group(1)},50)"',
|
| 70 |
svg_html
|
| 71 |
)
|
| 72 |
-
# Envolver en contenedor
|
| 73 |
diagram_html += f'<div class="arc-diagram-container">{svg_html}</div>'
|
| 74 |
return diagram_html
|
| 75 |
|
|
@@ -82,6 +80,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 82 |
"""
|
| 83 |
Interfaz principal para la visualización de diagramas de arco
|
| 84 |
(Texto Base vs Iteraciones).
|
|
|
|
| 85 |
"""
|
| 86 |
# CSS para layout vertical y estable
|
| 87 |
st.markdown("""
|
|
@@ -117,27 +116,30 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 117 |
with tabs[0]:
|
| 118 |
st.subheader("Análisis de Texto Base")
|
| 119 |
|
| 120 |
-
# Botón
|
| 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 |
|
| 126 |
-
#
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
#
|
| 135 |
-
if
|
| 136 |
if not arc_state["base_text"].strip():
|
| 137 |
st.warning("Ingrese un texto para analizar.")
|
| 138 |
else:
|
| 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
|
|
@@ -182,22 +184,24 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 182 |
else:
|
| 183 |
st.info("No hay diagrama base disponible.")
|
| 184 |
|
| 185 |
-
#
|
| 186 |
-
st.
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
| 196 |
if not arc_state["iteration_text"].strip():
|
| 197 |
st.warning("Ingrese texto de iteración.")
|
| 198 |
else:
|
| 199 |
try:
|
| 200 |
-
# Procesar con spaCy
|
| 201 |
doc_iter = nlp_models[lang_code](arc_state["iteration_text"])
|
| 202 |
arc_html_iter = display_arc_diagram(doc_iter)
|
| 203 |
arc_state["iteration_diagram"] = arc_html_iter
|
|
|
|
| 5 |
import logging
|
| 6 |
from spacy import displacy
|
| 7 |
|
|
|
|
| 8 |
from ..morphosyntax.morphosyntax_process import perform_advanced_morphosyntactic_analysis
|
| 9 |
from ..database.morphosyntax_iterative_mongo_db import (
|
| 10 |
store_student_morphosyntax_base,
|
|
|
|
| 68 |
lambda m: f'<g transform="translate({m.group(1)},50)"',
|
| 69 |
svg_html
|
| 70 |
)
|
|
|
|
| 71 |
diagram_html += f'<div class="arc-diagram-container">{svg_html}</div>'
|
| 72 |
return diagram_html
|
| 73 |
|
|
|
|
| 80 |
"""
|
| 81 |
Interfaz principal para la visualización de diagramas de arco
|
| 82 |
(Texto Base vs Iteraciones).
|
| 83 |
+
Se usan formularios (st.form) para minimizar el “temblor” al pulsar botones.
|
| 84 |
"""
|
| 85 |
# CSS para layout vertical y estable
|
| 86 |
st.markdown("""
|
|
|
|
| 116 |
with tabs[0]:
|
| 117 |
st.subheader("Análisis de Texto Base")
|
| 118 |
|
| 119 |
+
# Botón "Nuevo Análisis"
|
| 120 |
if st.button("Nuevo Análisis", key="btn_reset_base"):
|
|
|
|
|
|
|
| 121 |
reset_arc_analysis_state()
|
| 122 |
+
# Si quieres recargar la app por completo:
|
| 123 |
+
# st.experimental_rerun()
|
| 124 |
|
| 125 |
+
# ------ Usamos un formulario para agrupar los widgets ------
|
| 126 |
+
with st.form("base_form"):
|
| 127 |
+
# Textarea de texto base
|
| 128 |
+
arc_state["base_text"] = st.text_area(
|
| 129 |
+
"Ingrese su texto inicial",
|
| 130 |
+
value=arc_state["base_text"],
|
| 131 |
+
key="base_text_input",
|
| 132 |
+
height=150
|
| 133 |
+
)
|
| 134 |
+
# Botón de submit
|
| 135 |
+
submitted_base = st.form_submit_button("Analizar Texto Base")
|
| 136 |
|
| 137 |
+
# Solo procesamos si se dio submit
|
| 138 |
+
if submitted_base:
|
| 139 |
if not arc_state["base_text"].strip():
|
| 140 |
st.warning("Ingrese un texto para analizar.")
|
| 141 |
else:
|
| 142 |
try:
|
|
|
|
| 143 |
doc = nlp_models[lang_code](arc_state["base_text"])
|
| 144 |
base_arc_html = display_arc_diagram(doc)
|
| 145 |
arc_state["base_diagram"] = base_arc_html
|
|
|
|
| 184 |
else:
|
| 185 |
st.info("No hay diagrama base disponible.")
|
| 186 |
|
| 187 |
+
# ------ Usamos un formulario para la iteración ------
|
| 188 |
+
with st.form("iteration_form"):
|
| 189 |
+
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 190 |
+
st.subheader("Texto de Iteración")
|
| 191 |
+
|
| 192 |
+
arc_state["iteration_text"] = st.text_area(
|
| 193 |
+
"Ingrese su nueva versión / iteración",
|
| 194 |
+
value=arc_state["iteration_text"],
|
| 195 |
+
height=150
|
| 196 |
+
)
|
| 197 |
+
submitted_iter = st.form_submit_button("Analizar Cambios")
|
| 198 |
+
|
| 199 |
+
# Procesar cuando el form se envíe
|
| 200 |
+
if submitted_iter:
|
| 201 |
if not arc_state["iteration_text"].strip():
|
| 202 |
st.warning("Ingrese texto de iteración.")
|
| 203 |
else:
|
| 204 |
try:
|
|
|
|
| 205 |
doc_iter = nlp_models[lang_code](arc_state["iteration_text"])
|
| 206 |
arc_html_iter = display_arc_diagram(doc_iter)
|
| 207 |
arc_state["iteration_diagram"] = arc_html_iter
|