AIdeaText commited on
Commit
90b58d4
1 Parent(s): 53c88bc

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 # Pasar morpho_t en lugar de t
85
  )
86
 
87
- try:
88
- if current_input:
89
- # Extraer los diagramas de arco del análisis
90
- doc = nlp_models[lang_code](current_input)
91
- advanced_analysis = perform_advanced_morphosyntactic_analysis(current_input, nlp_models[lang_code])
92
-
93
- # Guardar el análisis
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.warning(morpho_t.get('warning_message', 'Please enter a text to analyze'))
106
- # Mostrar resultados previos si existen
107
- elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
108
- display_morphosyntax_results(
109
- st.session_state.morphosyntax_result,
110
- lang_code,
111
- morpho_t
112
- )
113
- else:
114
- st.info(morpho_t.get('morpho_initial_message', 'Enter text to begin analysis'))
 
 
 
 
 
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):