Spaces:
Running
Running
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -30,18 +30,19 @@ from ..database.morphosintaxis_export import export_user_interactions
|
|
| 30 |
import logging
|
| 31 |
logger = logging.getLogger(__name__)
|
| 32 |
|
|
|
|
| 33 |
def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
| 34 |
try:
|
| 35 |
-
# 1. Inicializar
|
| 36 |
if 'morphosyntax_state' not in st.session_state:
|
| 37 |
st.session_state.morphosyntax_state = {
|
| 38 |
'input_text': "",
|
| 39 |
-
'
|
| 40 |
'last_analysis': None
|
| 41 |
}
|
| 42 |
-
|
| 43 |
# 2. Campo de entrada de texto con key 煤nica basada en el contador
|
| 44 |
-
input_key = f"morpho_input_{st.session_state.morphosyntax_state['
|
| 45 |
|
| 46 |
sentence_input = st.text_area(
|
| 47 |
morpho_t.get('morpho_input_label', 'Enter text to analyze'),
|
|
@@ -56,11 +57,11 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 56 |
# 4. Crear columnas para el bot贸n
|
| 57 |
col1, col2, col3 = st.columns([2,1,2])
|
| 58 |
|
| 59 |
-
# 5. Bot贸n de an谩lisis
|
| 60 |
-
with
|
| 61 |
analyze_button = st.button(
|
| 62 |
morpho_t.get('morpho_analyze_button', 'Analyze Morphosyntax'),
|
| 63 |
-
key=f"morpho_button_{st.session_state.morphosyntax_state['
|
| 64 |
use_container_width=True
|
| 65 |
)
|
| 66 |
|
|
@@ -84,7 +85,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 84 |
}
|
| 85 |
|
| 86 |
# Incrementar el contador de an谩lisis
|
| 87 |
-
st.session_state.morphosyntax_state['
|
| 88 |
|
| 89 |
# Guardar el an谩lisis en la base de datos
|
| 90 |
if store_student_morphosyntax_result(
|
|
@@ -120,6 +121,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 120 |
except Exception as e:
|
| 121 |
logger.error(f"Error general en display_morphosyntax_interface: {str(e)}")
|
| 122 |
st.error("Se produjo un error. Por favor, intente de nuevo.")
|
|
|
|
| 123 |
|
| 124 |
############################################################################################################
|
| 125 |
def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
|
|
| 30 |
import logging
|
| 31 |
logger = logging.getLogger(__name__)
|
| 32 |
|
| 33 |
+
############################################################################################################
|
| 34 |
def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
| 35 |
try:
|
| 36 |
+
# 1. Inicializar el estado morfosint谩ctico si no existe
|
| 37 |
if 'morphosyntax_state' not in st.session_state:
|
| 38 |
st.session_state.morphosyntax_state = {
|
| 39 |
'input_text': "",
|
| 40 |
+
'analysis_count': 0,
|
| 41 |
'last_analysis': None
|
| 42 |
}
|
| 43 |
+
|
| 44 |
# 2. Campo de entrada de texto con key 煤nica basada en el contador
|
| 45 |
+
input_key = f"morpho_input_{st.session_state.morphosyntax_state['analysis_count']}"
|
| 46 |
|
| 47 |
sentence_input = st.text_area(
|
| 48 |
morpho_t.get('morpho_input_label', 'Enter text to analyze'),
|
|
|
|
| 57 |
# 4. Crear columnas para el bot贸n
|
| 58 |
col1, col2, col3 = st.columns([2,1,2])
|
| 59 |
|
| 60 |
+
# 5. Bot贸n de an谩lisis en la columna central
|
| 61 |
+
with col2:
|
| 62 |
analyze_button = st.button(
|
| 63 |
morpho_t.get('morpho_analyze_button', 'Analyze Morphosyntax'),
|
| 64 |
+
key=f"morpho_button_{st.session_state.morphosyntax_state['analysis_count']}",
|
| 65 |
use_container_width=True
|
| 66 |
)
|
| 67 |
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
# Incrementar el contador de an谩lisis
|
| 88 |
+
st.session_state.morphosyntax_state['analysis_count'] += 1
|
| 89 |
|
| 90 |
# Guardar el an谩lisis en la base de datos
|
| 91 |
if store_student_morphosyntax_result(
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
logger.error(f"Error general en display_morphosyntax_interface: {str(e)}")
|
| 123 |
st.error("Se produjo un error. Por favor, intente de nuevo.")
|
| 124 |
+
st.error(f"Detalles del error: {str(e)}") # A帽adido para mejor debugging
|
| 125 |
|
| 126 |
############################################################################################################
|
| 127 |
def display_morphosyntax_results(result, lang_code, morpho_t):
|