Spaces:
Sleeping
Sleeping
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -57,9 +57,9 @@ def display_morphosyntax_interface(lang_code, nlp_models, t):
|
|
| 57 |
on_change=lambda: setattr(st.session_state, input_key, st.session_state[f"text_area_{lang_code}"])
|
| 58 |
)
|
| 59 |
|
| 60 |
-
# Bot贸n de an谩lisis
|
| 61 |
if st.button(morpho_t.get('analyze_button', 'Analyze text'), key=f"analyze_button_{lang_code}"):
|
| 62 |
current_input = st.session_state[input_key]
|
|
|
|
| 63 |
if current_input:
|
| 64 |
try:
|
| 65 |
# Procesar el texto
|
|
@@ -70,48 +70,43 @@ def display_morphosyntax_interface(lang_code, nlp_models, t):
|
|
| 70 |
current_input,
|
| 71 |
nlp_models[lang_code]
|
| 72 |
)
|
| 73 |
-
|
| 74 |
# Guardar resultado en el estado de la sesi贸n
|
| 75 |
st.session_state.morphosyntax_result = {
|
| 76 |
'doc': doc,
|
| 77 |
'advanced_analysis': advanced_analysis
|
| 78 |
}
|
| 79 |
-
|
| 80 |
# Mostrar resultados
|
| 81 |
display_morphosyntax_results(
|
| 82 |
st.session_state.morphosyntax_result,
|
| 83 |
lang_code,
|
| 84 |
-
morpho_t
|
| 85 |
)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
if store_student_morphosyntax_result(
|
| 95 |
-
username=st.session_state.username,
|
| 96 |
-
text=current_input,
|
| 97 |
-
arc_diagrams=advanced_analysis['arc_diagram']
|
| 98 |
-
):
|
| 99 |
-
st.success(morpho_t.get('success_message', 'Analysis saved successfully'))
|
| 100 |
-
else:
|
| 101 |
-
st.error(morpho_t.get('error_message', 'Error saving analysis'))
|
| 102 |
-
except Exception as e:
|
| 103 |
-
st.error(morpho_t.get('error_processing', f'Error processing text: {str(e)}'))
|
| 104 |
else:
|
| 105 |
-
st.
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
############################################################################################################
|
| 117 |
def display_morphosyntax_results(result, lang_code, t):
|
|
|
|
| 57 |
on_change=lambda: setattr(st.session_state, input_key, st.session_state[f"text_area_{lang_code}"])
|
| 58 |
)
|
| 59 |
|
|
|
|
| 60 |
if st.button(morpho_t.get('analyze_button', 'Analyze text'), key=f"analyze_button_{lang_code}"):
|
| 61 |
current_input = st.session_state[input_key]
|
| 62 |
+
|
| 63 |
if current_input:
|
| 64 |
try:
|
| 65 |
# Procesar el texto
|
|
|
|
| 70 |
current_input,
|
| 71 |
nlp_models[lang_code]
|
| 72 |
)
|
| 73 |
+
|
| 74 |
# Guardar resultado en el estado de la sesi贸n
|
| 75 |
st.session_state.morphosyntax_result = {
|
| 76 |
'doc': doc,
|
| 77 |
'advanced_analysis': advanced_analysis
|
| 78 |
}
|
| 79 |
+
|
| 80 |
# Mostrar resultados
|
| 81 |
display_morphosyntax_results(
|
| 82 |
st.session_state.morphosyntax_result,
|
| 83 |
lang_code,
|
| 84 |
+
morpho_t
|
| 85 |
)
|
| 86 |
|
| 87 |
+
# Guardar el an谩lisis en la base de datos
|
| 88 |
+
if store_student_morphosyntax_result(
|
| 89 |
+
username=st.session_state.username,
|
| 90 |
+
text=current_input,
|
| 91 |
+
arc_diagrams=advanced_analysis['arc_diagram']
|
| 92 |
+
):
|
| 93 |
+
st.success(morpho_t.get('success_message', 'Analysis saved successfully'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
else:
|
| 95 |
+
st.error(morpho_t.get('error_message', 'Error saving analysis'))
|
| 96 |
+
|
| 97 |
+
except Exception as e:
|
| 98 |
+
st.error(morpho_t.get('error_processing', f'Error processing text: {str(e)}'))
|
| 99 |
+
else:
|
| 100 |
+
st.warning(morpho_t.get('warning_message', 'Please enter a text to analyze'))
|
| 101 |
+
# Si no se presion贸 el bot贸n, verificar si hay resultados previos
|
| 102 |
+
elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
|
| 103 |
+
display_morphosyntax_results(
|
| 104 |
+
st.session_state.morphosyntax_result,
|
| 105 |
+
lang_code,
|
| 106 |
+
morpho_t
|
| 107 |
+
)
|
| 108 |
+
else:
|
| 109 |
+
st.info(morpho_t.get('morpho_initial_message', 'Enter text to begin analysis'))
|
| 110 |
|
| 111 |
############################################################################################################
|
| 112 |
def display_morphosyntax_results(result, lang_code, t):
|