Spaces:
Running
Running
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import re
|
|
@@ -12,6 +12,8 @@ from ..database.morphosyntax_iterative_mongo_db import (
|
|
| 12 |
store_student_morphosyntax_iteration,
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
|
| 17 |
###########################################################################
|
|
@@ -57,7 +59,7 @@ def display_arc_diagram(doc):
|
|
| 57 |
"word_spacing": 30
|
| 58 |
}
|
| 59 |
)
|
| 60 |
-
# Ajustar tama帽os
|
| 61 |
svg_html = svg_html.replace('height="375"', 'height="200"')
|
| 62 |
svg_html = re.sub(
|
| 63 |
r'<svg[^>]*>',
|
|
@@ -81,9 +83,9 @@ def display_arc_diagram(doc):
|
|
| 81 |
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
|
| 87 |
st.markdown("""
|
| 88 |
<style>
|
| 89 |
.stTextArea textarea {
|
|
@@ -110,31 +112,27 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 110 |
initialize_arc_analysis_state()
|
| 111 |
arc_state = st.session_state.arc_analysis_state
|
| 112 |
|
| 113 |
-
# 2)
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# =================== PESTA脩A 1: Texto Base ==========================
|
| 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 |
-
"
|
| 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
|
| 136 |
if not arc_state["base_text"].strip():
|
| 137 |
-
st.warning("Ingrese un texto para
|
| 138 |
else:
|
| 139 |
try:
|
| 140 |
# Procesar con spaCy
|
|
@@ -154,47 +152,60 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 154 |
)
|
| 155 |
if base_id:
|
| 156 |
arc_state["base_id"] = base_id
|
| 157 |
-
|
|
|
|
| 158 |
|
| 159 |
except Exception as exc:
|
| 160 |
-
st.error("Error
|
| 161 |
logger.error(f"Error en an谩lisis base: {str(exc)}")
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Mostrar diagrama base
|
| 164 |
if arc_state["base_diagram"]:
|
| 165 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 166 |
-
st.markdown("#### Diagrama de
|
| 167 |
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
# ================== PESTA脩A 2: Iteraciones ==========================
|
| 170 |
with tabs[1]:
|
| 171 |
-
st.subheader("
|
| 172 |
|
| 173 |
# Verificar que exista un texto base
|
| 174 |
if not arc_state["base_id"]:
|
| 175 |
-
st.info(
|
|
|
|
| 176 |
return
|
| 177 |
|
| 178 |
# --- 1) Mostrar SIEMPRE el diagrama base arriba ---
|
| 179 |
-
st.markdown("#### Diagrama de
|
| 180 |
if arc_state["base_diagram"]:
|
| 181 |
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
| 182 |
else:
|
| 183 |
-
st.info("
|
| 184 |
|
| 185 |
# --- 2) Caja de texto para la iteraci贸n ---
|
| 186 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 187 |
-
st.subheader("
|
|
|
|
| 188 |
arc_state["iteration_text"] = st.text_area(
|
| 189 |
-
"
|
| 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("
|
| 198 |
else:
|
| 199 |
try:
|
| 200 |
# Procesar con spaCy
|
|
@@ -215,14 +226,16 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 215 |
arc_diagrams=analysis_iter["arc_diagrams"]
|
| 216 |
)
|
| 217 |
if iteration_id:
|
| 218 |
-
|
|
|
|
| 219 |
|
| 220 |
except Exception as exc:
|
| 221 |
-
st.error("Error procesando
|
| 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)
|
|
|
|
| 1 |
+
#morphosyntax_interface.py
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
import re
|
|
|
|
| 12 |
store_student_morphosyntax_iteration,
|
| 13 |
)
|
| 14 |
|
| 15 |
+
from translations import get_translations
|
| 16 |
+
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
| 19 |
###########################################################################
|
|
|
|
| 59 |
"word_spacing": 30
|
| 60 |
}
|
| 61 |
)
|
| 62 |
+
# Ajustar tama帽os en el SVG resultante
|
| 63 |
svg_html = svg_html.replace('height="375"', 'height="200"')
|
| 64 |
svg_html = re.sub(
|
| 65 |
r'<svg[^>]*>',
|
|
|
|
| 83 |
def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
| 84 |
"""
|
| 85 |
Interfaz principal para la visualizaci贸n de diagramas de arco
|
| 86 |
+
(Texto Base vs Iteraciones), usando traducciones con morpho_t.
|
| 87 |
"""
|
| 88 |
+
# CSS para layout y estilo
|
| 89 |
st.markdown("""
|
| 90 |
<style>
|
| 91 |
.stTextArea textarea {
|
|
|
|
| 112 |
initialize_arc_analysis_state()
|
| 113 |
arc_state = st.session_state.arc_analysis_state
|
| 114 |
|
| 115 |
+
# 2) Crear pesta帽as con etiquetas traducidas
|
| 116 |
+
tab_text_base = morpho_t.get('tab_text_baseline', 'Ingresa la primera versi贸n de tu texto')
|
| 117 |
+
tab_iterations = morpho_t.get('tab_iterations', 'Produce nuevas versiones de tu primer texto')
|
| 118 |
+
tabs = st.tabs([tab_text_base, tab_iterations])
|
| 119 |
|
| 120 |
# =================== PESTA脩A 1: Texto Base ==========================
|
| 121 |
with tabs[0]:
|
| 122 |
+
# st.subheader(morpho_t.get('analysis_base_subheader', "An谩lisis de Texto Base"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Textarea de texto base
|
| 125 |
arc_state["base_text"] = st.text_area(
|
| 126 |
+
morpho_t.get('input_baseline_text', "Ingresa el primer texto para analizarlo"),
|
| 127 |
value=arc_state["base_text"],
|
| 128 |
key="base_text_input",
|
| 129 |
height=150
|
| 130 |
)
|
| 131 |
|
| 132 |
# Bot贸n para analizar texto base
|
| 133 |
+
if st.button(morpho_t.get('btn_analyze_baseline', "Analizar la primera versi贸n de tu texto"), key="btn_analyze_base"):
|
| 134 |
if not arc_state["base_text"].strip():
|
| 135 |
+
st.warning(morpho_t.get('warn_enter_text', "Ingrese un texto nuevo para analizarlo."))
|
| 136 |
else:
|
| 137 |
try:
|
| 138 |
# Procesar con spaCy
|
|
|
|
| 152 |
)
|
| 153 |
if base_id:
|
| 154 |
arc_state["base_id"] = base_id
|
| 155 |
+
saved_msg = morpho_t.get('analysis_base_saved', "An谩lisis base guardado. ID: {base_id}")
|
| 156 |
+
st.success(saved_msg.format(base_id=base_id))
|
| 157 |
|
| 158 |
except Exception as exc:
|
| 159 |
+
st.error(morpho_t.get('error_processing_baseline', "Error al procesar el texto inicial"))
|
| 160 |
logger.error(f"Error en an谩lisis base: {str(exc)}")
|
| 161 |
|
| 162 |
+
# Bot贸n para iniciar nuevo an谩lisis
|
| 163 |
+
if st.button(morpho_t.get('btn_new_morpho_analysis', "Nuevo an谩lisis morfosint谩tico"), key="btn_reset_base"):
|
| 164 |
+
# Si fuera necesario recargar la app por completo:
|
| 165 |
+
# st.experimental_rerun()
|
| 166 |
+
reset_arc_analysis_state()
|
| 167 |
+
|
| 168 |
# Mostrar diagrama base
|
| 169 |
if arc_state["base_diagram"]:
|
| 170 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 171 |
+
st.markdown(f"#### {morpho_t.get('arc_diagram_baseline_label', 'Diagrama de arco del texto inicial')}")
|
| 172 |
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
| 173 |
+
else:
|
| 174 |
+
if arc_state["base_text"].strip():
|
| 175 |
+
# Solo mostrar si ya hay texto base pero no se ha procesado
|
| 176 |
+
st.info(morpho_t.get('baseline_diagram_not_available', "Diagrama de arco del texto inicial no disponible."))
|
| 177 |
|
| 178 |
# ================== PESTA脩A 2: Iteraciones ==========================
|
| 179 |
with tabs[1]:
|
| 180 |
+
#st.subheader(morpho_t.get('iteration_text_subheader', "Nueva versi贸n del texto inicial"))
|
| 181 |
|
| 182 |
# Verificar que exista un texto base
|
| 183 |
if not arc_state["base_id"]:
|
| 184 |
+
st.info(morpho_t.get('info_first_analyze_base',
|
| 185 |
+
"Verifica la existencia de un texto anterior."))
|
| 186 |
return
|
| 187 |
|
| 188 |
# --- 1) Mostrar SIEMPRE el diagrama base arriba ---
|
| 189 |
+
st.markdown(f"#### {morpho_t.get('arc_diagram_base_label', 'Diagrama de arco del texto inicial')}")
|
| 190 |
if arc_state["base_diagram"]:
|
| 191 |
st.write(arc_state["base_diagram"], unsafe_allow_html=True)
|
| 192 |
else:
|
| 193 |
+
st.info(morpho_t.get('baseline_diagram_not_available', "Diagrama de arco del texto inicial no disponible."))
|
| 194 |
|
| 195 |
# --- 2) Caja de texto para la iteraci贸n ---
|
| 196 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 197 |
+
#st.subheader(morpho_t.get('iteration_text_subheader', "Ingresa una nueva versi贸n del texto inicial y compara los arcos de ambos textos"))
|
| 198 |
+
|
| 199 |
arc_state["iteration_text"] = st.text_area(
|
| 200 |
+
morpho_t.get('input_iteration_text', "Ingresa una nueva versi贸n del texto inicial y compara los arcos de ambos textos"),
|
| 201 |
value=arc_state["iteration_text"],
|
| 202 |
height=150
|
| 203 |
)
|
| 204 |
|
| 205 |
# Bot贸n para analizar iteraci贸n
|
| 206 |
+
if st.button(morpho_t.get('btn_analyze_iteration', "Analizar Cambios"), key="btn_analyze_iteration"):
|
| 207 |
if not arc_state["iteration_text"].strip():
|
| 208 |
+
st.warning(morpho_t.get('warn_enter_iteration_text', "Ingresa una nueva versi贸n del texto inicial y compara los arcos de ambos textos."))
|
| 209 |
else:
|
| 210 |
try:
|
| 211 |
# Procesar con spaCy
|
|
|
|
| 226 |
arc_diagrams=analysis_iter["arc_diagrams"]
|
| 227 |
)
|
| 228 |
if iteration_id:
|
| 229 |
+
saved_iter_msg = morpho_t.get('iteration_saved', "Cambios guardados correctamente. ID: {iteration_id}")
|
| 230 |
+
st.success(saved_iter_msg.format(iteration_id=iteration_id))
|
| 231 |
|
| 232 |
except Exception as exc:
|
| 233 |
+
st.error(morpho_t.get('error_iteration', "Error procesando los nuevos cambios"))
|
| 234 |
logger.error(f"Error en iteraci贸n: {str(exc)}")
|
| 235 |
|
| 236 |
+
|
| 237 |
# --- 3) Mostrar diagrama de iteraci贸n debajo ---
|
| 238 |
if arc_state["iteration_diagram"]:
|
| 239 |
st.markdown("<hr class='divider'>", unsafe_allow_html=True)
|
| 240 |
+
st.markdown(f"#### {morpho_t.get('arc_diagram_iteration_label', 'Diagrama de Arco (Iteraci贸n)')}")
|
| 241 |
+
st.write(arc_state["iteration_diagram"], unsafe_allow_html=True)
|