Update modules/semantic/semantic_live_interface.py
Browse files
modules/semantic/semantic_live_interface.py
CHANGED
@@ -68,9 +68,9 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
68 |
with col2:
|
69 |
st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
with st.spinner(semantic_t.get('processing', 'Procesando...')):
|
75 |
# Realizar análisis
|
76 |
analysis_result = process_semantic_input(
|
@@ -92,58 +92,57 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
92 |
analysis_result['analysis']
|
93 |
)
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
try:
|
147 |
# Container para el grafo con estilos mejorados
|
148 |
st.markdown(
|
149 |
"""
|
@@ -193,17 +192,13 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
193 |
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
194 |
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
195 |
""")
|
196 |
-
|
197 |
-
|
198 |
-
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
199 |
-
else:
|
200 |
-
st.info(semantic_t.get('no_graph', 'No graph available'))
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
|
206 |
except Exception as e:
|
207 |
logger.error(f"Error general en interfaz semántica en vivo: {str(e)}")
|
208 |
st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|
209 |
-
|
|
|
68 |
with col2:
|
69 |
st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
|
70 |
|
71 |
+
try:
|
72 |
+
# Procesar análisis cuando se presiona el botón
|
73 |
+
if analyze_button and text_input:
|
74 |
with st.spinner(semantic_t.get('processing', 'Procesando...')):
|
75 |
# Realizar análisis
|
76 |
analysis_result = process_semantic_input(
|
|
|
92 |
analysis_result['analysis']
|
93 |
)
|
94 |
|
95 |
+
# Mostrar resultados (ya sea nuevos o previos)
|
96 |
+
if 'last_result' in st.session_state.semantic_live_state and \
|
97 |
+
st.session_state.semantic_live_state['last_result'] is not None:
|
98 |
+
|
99 |
+
analysis = st.session_state.semantic_live_state['last_result']['analysis']
|
100 |
+
|
101 |
+
# Mostrar conceptos clave en formato horizontal
|
102 |
+
if 'key_concepts' in analysis and analysis['key_concepts']:
|
103 |
+
st.markdown(
|
104 |
+
"""
|
105 |
+
<style>
|
106 |
+
.concept-table {
|
107 |
+
display: flex;
|
108 |
+
flex-wrap: wrap;
|
109 |
+
gap: 10px;
|
110 |
+
margin-bottom: 20px;
|
111 |
+
}
|
112 |
+
.concept-item {
|
113 |
+
background-color: #f0f2f6;
|
114 |
+
border-radius: 5px;
|
115 |
+
padding: 8px 12px;
|
116 |
+
display: flex;
|
117 |
+
align-items: center;
|
118 |
+
gap: 8px;
|
119 |
+
}
|
120 |
+
.concept-name {
|
121 |
+
font-weight: bold;
|
122 |
+
}
|
123 |
+
.concept-freq {
|
124 |
+
color: #666;
|
125 |
+
font-size: 0.9em;
|
126 |
+
}
|
127 |
+
</style>
|
128 |
+
""",
|
129 |
+
unsafe_allow_html=True
|
130 |
+
)
|
131 |
+
|
132 |
+
# Crear la visualización horizontal de conceptos
|
133 |
+
concepts_html = '<div class="concept-table">'
|
134 |
+
for concept, freq in analysis['key_concepts']:
|
135 |
+
concepts_html += f'''
|
136 |
+
<div class="concept-item">
|
137 |
+
<span class="concept-name">{concept}</span>
|
138 |
+
<span class="concept-freq">({freq:.2f})</span>
|
139 |
+
</div>
|
140 |
+
'''
|
141 |
+
concepts_html += '</div>'
|
142 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
143 |
+
|
144 |
+
# Mostrar gráfico de conceptos
|
145 |
+
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
|
|
146 |
# Container para el grafo con estilos mejorados
|
147 |
st.markdown(
|
148 |
"""
|
|
|
192 |
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
193 |
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
194 |
""")
|
195 |
+
else:
|
196 |
+
st.info(semantic_t.get('no_graph', 'No graph available'))
|
|
|
|
|
|
|
197 |
|
198 |
+
except Exception as e:
|
199 |
+
logger.error(f"Error processing or displaying results: {str(e)}")
|
200 |
+
st.error(semantic_t.get('error_processing', f'Error al procesar o mostrar resultados: {str(e)}'))
|
201 |
|
202 |
except Exception as e:
|
203 |
logger.error(f"Error general en interfaz semántica en vivo: {str(e)}")
|
204 |
st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|
|