Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_live_interface.py
Browse files
modules/semantic/semantic_live_interface.py
CHANGED
|
@@ -97,117 +97,96 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
| 97 |
if analysis_result and not analysis_result.get('success'):
|
| 98 |
st.error(analysis_result.get('message', 'Error en el análisis'))
|
| 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 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
}
|
| 153 |
-
.results-container {
|
| 154 |
-
background-color: white;
|
| 155 |
-
border-radius: 10px;
|
| 156 |
-
overflow: hidden;
|
| 157 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 158 |
-
}
|
| 159 |
-
</style>
|
| 160 |
-
""", unsafe_allow_html=True)
|
| 161 |
-
|
| 162 |
-
# Iniciar contenedor principal
|
| 163 |
-
st.markdown('<div class="results-container">', unsafe_allow_html=True)
|
| 164 |
-
|
| 165 |
-
# Crear la visualización horizontal de conceptos
|
| 166 |
-
concepts_html = ['<div class="concept-table">']
|
| 167 |
-
concepts_html.extend(
|
| 168 |
-
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
| 169 |
-
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
| 170 |
-
for concept, freq in analysis['key_concepts']
|
| 171 |
-
)
|
| 172 |
-
concepts_html.append('</div>')
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
st.image(
|
| 182 |
-
analysis['concept_graph'],
|
| 183 |
-
use_container_width=True,
|
| 184 |
-
caption=semantic_t.get(
|
| 185 |
-
'graph_description',
|
| 186 |
-
'Visualización de relaciones entre conceptos clave identificados en el texto.'
|
| 187 |
-
)
|
| 188 |
)
|
|
|
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
| 97 |
if analysis_result and not analysis_result.get('success'):
|
| 98 |
st.error(analysis_result.get('message', 'Error en el análisis'))
|
| 99 |
|
| 100 |
+
# Columna derecha: Visualización de resultados
|
| 101 |
+
with result_col:
|
| 102 |
+
st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
|
| 103 |
|
| 104 |
+
if 'last_result' in st.session_state.semantic_live_state and \
|
| 105 |
+
st.session_state.semantic_live_state['last_result'] is not None:
|
| 106 |
+
|
| 107 |
+
analysis = st.session_state.semantic_live_state['last_result']['analysis']
|
| 108 |
+
|
| 109 |
+
if 'key_concepts' in analysis and analysis['key_concepts'] and \
|
| 110 |
+
'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 111 |
|
| 112 |
+
# Estilos unificados en un solo bloque
|
| 113 |
+
st.markdown("""
|
| 114 |
+
<style>
|
| 115 |
+
.unified-container {
|
| 116 |
+
background-color: white;
|
| 117 |
+
border-radius: 10px;
|
| 118 |
+
overflow: hidden;
|
| 119 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 120 |
+
}
|
| 121 |
+
.concept-table {
|
| 122 |
+
display: flex;
|
| 123 |
+
flex-wrap: wrap;
|
| 124 |
+
gap: 10px;
|
| 125 |
+
padding: 15px;
|
| 126 |
+
background-color: #f8f9fa;
|
| 127 |
+
}
|
| 128 |
+
.concept-item {
|
| 129 |
+
background-color: white;
|
| 130 |
+
border-radius: 5px;
|
| 131 |
+
padding: 8px 12px;
|
| 132 |
+
display: flex;
|
| 133 |
+
align-items: center;
|
| 134 |
+
gap: 8px;
|
| 135 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 136 |
+
}
|
| 137 |
+
.concept-name { font-weight: 500; color: #1f2937; }
|
| 138 |
+
.concept-freq { color: #6b7280; font-size: 0.9em; }
|
| 139 |
+
.graph-section { padding: 20px; }
|
| 140 |
+
</style>
|
| 141 |
+
""", unsafe_allow_html=True)
|
| 142 |
+
|
| 143 |
+
# Contenedor unificado para conceptos y grafo
|
| 144 |
+
with st.container():
|
| 145 |
+
# Conceptos
|
| 146 |
+
concepts_html = f"""
|
| 147 |
+
<div class="unified-container">
|
| 148 |
+
<div class="concept-table">
|
| 149 |
+
{''.join(f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
| 150 |
+
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
| 151 |
+
for concept, freq in analysis['key_concepts'])}
|
| 152 |
+
</div>
|
| 153 |
+
<div class="graph-section">
|
| 154 |
+
"""
|
| 155 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
+
# Grafo
|
| 158 |
+
st.image(
|
| 159 |
+
analysis['concept_graph'],
|
| 160 |
+
use_container_width=True,
|
| 161 |
+
caption=semantic_t.get(
|
| 162 |
+
'graph_description',
|
| 163 |
+
'Visualización de relaciones entre conceptos clave identificados en el texto.'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
)
|
| 165 |
+
)
|
| 166 |
|
| 167 |
+
st.markdown('</div></div>', unsafe_allow_html=True)
|
| 168 |
+
|
| 169 |
+
# Botones y controles fuera del contenedor principal
|
| 170 |
+
button_col, spacer_col = st.columns([1,4])
|
| 171 |
+
with button_col:
|
| 172 |
+
st.download_button(
|
| 173 |
+
label="📥 " + semantic_t.get('download_graph', "Download"),
|
| 174 |
+
data=analysis['concept_graph'],
|
| 175 |
+
file_name="semantic_live_graph.png",
|
| 176 |
+
mime="image/png",
|
| 177 |
+
use_container_width=True
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
with st.expander("📊 " + semantic_t.get('graph_help', "Graph Interpretation")):
|
| 181 |
+
st.markdown("""
|
| 182 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 183 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 184 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 185 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 186 |
+
""")
|
| 187 |
+
else:
|
| 188 |
+
st.info(semantic_t.get('no_graph', 'No hay datos para mostrar'))
|
| 189 |
+
|
| 190 |
+
except Exception as e:
|
| 191 |
+
logger.error(f"Error general en interfaz semántica en vivo: {str(e)}")
|
| 192 |
+
st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|