AIdeaText commited on
Commit
49369ea
verified
1 Parent(s): 835fc8a

Update modules/semantic/semantic_live_interface.py

Browse files
modules/semantic/semantic_live_interface.py CHANGED
@@ -35,14 +35,14 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
35
  # 2. Crear columnas con nueva proporci贸n (1:3)
36
  input_col, result_col = st.columns([1, 3])
37
 
38
- # Columna izquierda: Entrada de texto (m谩s compacta)
39
  with input_col:
40
  st.subheader(semantic_t.get('enter_text', 'Ingrese su texto'))
41
 
42
  # 脕rea de texto ajustada al nuevo ancho
43
  text_input = st.text_area(
44
  semantic_t.get('text_input_label', 'Escriba o pegue su texto aqu铆'),
45
- height=500, # Aumentado para compensar el ancho reducido
46
  key="semantic_live_text",
47
  value=st.session_state.semantic_live_state.get('current_text', '')
48
  )
@@ -50,7 +50,7 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
50
  # Actualizar el texto actual en el estado
51
  st.session_state.semantic_live_state['current_text'] = text_input
52
 
53
- # Bot贸n de an谩lisis
54
  analyze_button = st.button(
55
  semantic_t.get('analyze_button', 'Analizar'),
56
  key="semantic_live_analyze",
@@ -60,19 +60,51 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
60
  use_container_width=True
61
  )
62
 
63
- # Columna derecha: Visualizaci贸n de resultados (m谩s amplia)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  with result_col:
65
  st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
66
 
 
67
  if 'last_result' in st.session_state.semantic_live_state and \
68
  st.session_state.semantic_live_state['last_result'] is not None:
69
 
70
  analysis = st.session_state.semantic_live_state['last_result']['analysis']
71
 
 
72
  if 'key_concepts' in analysis and analysis['key_concepts'] and \
73
  'concept_graph' in analysis and analysis['concept_graph'] is not None:
74
 
75
- # Estilos adaptados al nuevo ancho
76
  st.markdown("""
77
  <style>
78
  .unified-container {
@@ -81,6 +113,7 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
81
  overflow: hidden;
82
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
83
  width: 100%;
 
84
  }
85
  .concept-table {
86
  display: flex;
@@ -109,41 +142,35 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
109
  }
110
  .graph-section {
111
  padding: 20px;
112
- display: flex;
113
- flex-direction: column;
114
- align-items: center;
115
  }
116
  </style>
117
  """, unsafe_allow_html=True)
118
 
119
- # Contenedor unificado para conceptos y grafo
120
  with st.container():
121
  # Conceptos
122
- concepts_html = f"""
123
  <div class="unified-container">
124
  <div class="concept-table">
125
- {''.join(f'<div class="concept-item"><span class="concept-name">{concept}</span>'
126
- f'<span class="concept-freq">({freq:.2f})</span></div>'
127
- for concept, freq in analysis['key_concepts'])}
128
- </div>
129
- <div class="graph-section">
130
  """
 
 
 
 
 
 
131
  st.markdown(concepts_html, unsafe_allow_html=True)
132
 
133
  # Grafo
134
- st.image(
135
- analysis['concept_graph'],
136
- use_container_width=True,
137
- caption=semantic_t.get(
138
- 'graph_description',
139
- 'Visualizaci贸n de relaciones entre conceptos clave identificados en el texto.'
140
  )
141
- )
142
-
143
- st.markdown('</div></div>', unsafe_allow_html=True)
144
 
145
- # Botones y controles ajustados al nuevo ancho
146
- button_col, spacer_col = st.columns([1,5]) # Ajustada la proporci贸n
147
  with button_col:
148
  st.download_button(
149
  label="馃摜 " + semantic_t.get('download_graph', "Download"),
@@ -165,4 +192,4 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
165
 
166
  except Exception as e:
167
  logger.error(f"Error general en interfaz sem谩ntica en vivo: {str(e)}")
168
- st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
 
35
  # 2. Crear columnas con nueva proporci贸n (1:3)
36
  input_col, result_col = st.columns([1, 3])
37
 
38
+ # Columna izquierda: Entrada de texto
39
  with input_col:
40
  st.subheader(semantic_t.get('enter_text', 'Ingrese su texto'))
41
 
42
  # 脕rea de texto ajustada al nuevo ancho
43
  text_input = st.text_area(
44
  semantic_t.get('text_input_label', 'Escriba o pegue su texto aqu铆'),
45
+ height=500,
46
  key="semantic_live_text",
47
  value=st.session_state.semantic_live_state.get('current_text', '')
48
  )
 
50
  # Actualizar el texto actual en el estado
51
  st.session_state.semantic_live_state['current_text'] = text_input
52
 
53
+ # Bot贸n de an谩lisis y procesamiento
54
  analyze_button = st.button(
55
  semantic_t.get('analyze_button', 'Analizar'),
56
  key="semantic_live_analyze",
 
60
  use_container_width=True
61
  )
62
 
63
+ # Procesar an谩lisis cuando se presiona el bot贸n
64
+ if analyze_button and text_input:
65
+ try:
66
+ with st.spinner(semantic_t.get('processing', 'Procesando...')):
67
+ # Realizar an谩lisis
68
+ analysis_result = process_semantic_input(
69
+ text_input,
70
+ lang_code,
71
+ nlp_models,
72
+ semantic_t
73
+ )
74
+
75
+ if analysis_result['success']:
76
+ # Guardar resultado en el estado
77
+ st.session_state.semantic_live_state['last_result'] = analysis_result
78
+ st.session_state.semantic_live_state['analysis_count'] += 1
79
+
80
+ # Guardar en base de datos
81
+ store_student_semantic_result(
82
+ st.session_state.username,
83
+ text_input,
84
+ analysis_result['analysis']
85
+ )
86
+ else:
87
+ st.error(analysis_result.get('message', 'Error en el an谩lisis'))
88
+
89
+ except Exception as e:
90
+ logger.error(f"Error en an谩lisis: {str(e)}")
91
+ st.error(semantic_t.get('error_processing', 'Error al procesar el texto'))
92
+
93
+ # Columna derecha: Visualizaci贸n de resultados
94
  with result_col:
95
  st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
96
 
97
+ # Mostrar resultados si existen
98
  if 'last_result' in st.session_state.semantic_live_state and \
99
  st.session_state.semantic_live_state['last_result'] is not None:
100
 
101
  analysis = st.session_state.semantic_live_state['last_result']['analysis']
102
 
103
+ # Verificar que tenemos datos para mostrar
104
  if 'key_concepts' in analysis and analysis['key_concepts'] and \
105
  'concept_graph' in analysis and analysis['concept_graph'] is not None:
106
 
107
+ # Estilos para la visualizaci贸n
108
  st.markdown("""
109
  <style>
110
  .unified-container {
 
113
  overflow: hidden;
114
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
115
  width: 100%;
116
+ margin-bottom: 1rem;
117
  }
118
  .concept-table {
119
  display: flex;
 
142
  }
143
  .graph-section {
144
  padding: 20px;
145
+ background-color: white;
 
 
146
  }
147
  </style>
148
  """, unsafe_allow_html=True)
149
 
150
+ # Mostrar conceptos y grafo
151
  with st.container():
152
  # Conceptos
153
+ concepts_html = """
154
  <div class="unified-container">
155
  <div class="concept-table">
 
 
 
 
 
156
  """
157
+ concepts_html += ''.join(
158
+ f'<div class="concept-item"><span class="concept-name">{concept}</span>'
159
+ f'<span class="concept-freq">({freq:.2f})</span></div>'
160
+ for concept, freq in analysis['key_concepts']
161
+ )
162
+ concepts_html += "</div></div>"
163
  st.markdown(concepts_html, unsafe_allow_html=True)
164
 
165
  # Grafo
166
+ if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
167
+ st.image(
168
+ analysis['concept_graph'],
169
+ use_container_width=True
 
 
170
  )
 
 
 
171
 
172
+ # Botones y controles
173
+ button_col, spacer_col = st.columns([1,5])
174
  with button_col:
175
  st.download_button(
176
  label="馃摜 " + semantic_t.get('download_graph', "Download"),
 
192
 
193
  except Exception as e:
194
  logger.error(f"Error general en interfaz sem谩ntica en vivo: {str(e)}")
195
+ st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))