Spaces:
Running
Running
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -5,6 +5,7 @@ import re
|
|
| 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,
|
|
@@ -41,8 +42,8 @@ def reset_arc_analysis_state():
|
|
| 41 |
###########################################################################
|
| 42 |
def display_arc_diagram(doc):
|
| 43 |
"""
|
| 44 |
-
Genera y retorna el HTML del diagrama de arco para un
|
| 45 |
-
No imprime directamente; retorna el HTML para usar con
|
| 46 |
"""
|
| 47 |
try:
|
| 48 |
diagram_html = ""
|
|
@@ -68,6 +69,7 @@ def display_arc_diagram(doc):
|
|
| 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,7 +82,6 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 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,30 +117,27 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 116 |
with tabs[0]:
|
| 117 |
st.subheader("Análisis de Texto Base")
|
| 118 |
|
| 119 |
-
# Botón
|
| 120 |
if st.button("Nuevo Análisis", key="btn_reset_base"):
|
| 121 |
-
|
| 122 |
-
# Si quieres recargar la app por completo:
|
| 123 |
# st.experimental_rerun()
|
|
|
|
| 124 |
|
| 125 |
-
#
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
arc_state["base_text"]
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
height=150
|
| 133 |
-
)
|
| 134 |
-
# Botón de submit
|
| 135 |
-
submitted_base = st.form_submit_button("Analizar Texto Base")
|
| 136 |
|
| 137 |
-
#
|
| 138 |
-
if
|
| 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,24 +182,22 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 184 |
else:
|
| 185 |
st.info("No hay diagrama base disponible.")
|
| 186 |
|
| 187 |
-
#
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
arc_state["iteration_text"]
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 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
|
|
@@ -229,4 +225,4 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 229 |
if arc_state["iteration_diagram"]:
|
| 230 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 231 |
st.markdown("#### Diagrama de Arco (Iteración)")
|
| 232 |
-
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,
|
|
|
|
| 42 |
###########################################################################
|
| 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 = ""
|
|
|
|
| 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 |
"""
|
| 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 |
with tabs[0]:
|
| 118 |
st.subheader("Análisis de Texto Base")
|
| 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 |
|
| 126 |
+
# Textarea de texto base
|
| 127 |
+
arc_state["base_text"] = st.text_area(
|
| 128 |
+
"Ingrese su texto inicial",
|
| 129 |
+
value=arc_state["base_text"],
|
| 130 |
+
key="base_text_input",
|
| 131 |
+
height=150
|
| 132 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
# Botón para analizar texto base
|
| 135 |
+
if st.button("Analizar Texto Base", key="btn_analyze_base"):
|
| 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 |
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.")
|
| 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
|
|
|
|
| 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)
|