Spaces:
Running
Running
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
|
@@ -52,7 +52,7 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 52 |
key=f"semantic_file_uploader_{st.session_state.semantic_state['analysis_count']}"
|
| 53 |
)
|
| 54 |
|
| 55 |
-
# Verificar si hay un archivo cargado y un análisis pendiente
|
| 56 |
if uploaded_file is not None and st.session_state.semantic_state.get('pending_analysis', False):
|
| 57 |
try:
|
| 58 |
with st.spinner(semantic_t.get('processing', 'Processing...')):
|
|
@@ -124,10 +124,10 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 124 |
# Mostrar mensaje sobre el análisis actual
|
| 125 |
st.info(
|
| 126 |
semantic_t.get('current_analysis_message',
|
| 127 |
-
|
| 128 |
-
|
| 129 |
)
|
| 130 |
-
|
| 131 |
display_semantic_results(
|
| 132 |
st.session_state.semantic_result,
|
| 133 |
lang_code,
|
|
@@ -204,7 +204,8 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 204 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 205 |
|
| 206 |
# Gráfico de conceptos
|
| 207 |
-
st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
|
|
|
| 208 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 209 |
try:
|
| 210 |
# Container para el grafo con estilos mejorados
|
|
@@ -227,6 +228,7 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 227 |
""",
|
| 228 |
unsafe_allow_html=True
|
| 229 |
)
|
|
|
|
| 230 |
|
| 231 |
with st.container():
|
| 232 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
|
@@ -240,57 +242,35 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 240 |
)
|
| 241 |
|
| 242 |
# Leyenda del grafo
|
| 243 |
-
st.caption(semantic_t.get(
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
))
|
| 247 |
|
| 248 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
# Contenedor para botones
|
| 251 |
col1, col2 = st.columns([1,4])
|
| 252 |
with col1:
|
| 253 |
st.download_button(
|
| 254 |
-
label="📥 " + semantic_t.get('
|
| 255 |
data=graph_bytes,
|
| 256 |
file_name="semantic_graph.png",
|
| 257 |
mime="image/png",
|
| 258 |
use_container_width=True
|
| 259 |
)
|
| 260 |
-
|
| 261 |
-
# Expandible con la interpretación
|
| 262 |
-
with st.expander("📊 " + semantic_t.get('graph_help', "Graph Interpretation")):
|
| 263 |
-
st.markdown("""
|
| 264 |
-
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 265 |
-
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 266 |
-
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 267 |
-
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 268 |
-
""")
|
| 269 |
|
| 270 |
except Exception as e:
|
| 271 |
logger.error(f"Error displaying graph: {str(e)}")
|
| 272 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
| 273 |
else:
|
| 274 |
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
########################################################################################
|
| 278 |
-
'''
|
| 279 |
-
# Botón de exportación al final
|
| 280 |
-
if 'semantic_analysis_counter' in st.session_state:
|
| 281 |
-
col1, col2, col3 = st.columns([2,1,2])
|
| 282 |
-
with col2:
|
| 283 |
-
if st.button(
|
| 284 |
-
semantic_t.get('export_button', 'Export Analysis'),
|
| 285 |
-
key=f"semantic_export_{st.session_state.semantic_analysis_counter}",
|
| 286 |
-
use_container_width=True
|
| 287 |
-
):
|
| 288 |
-
pdf_buffer = export_user_interactions(st.session_state.username, 'semantic')
|
| 289 |
-
st.download_button(
|
| 290 |
-
label=semantic_t.get('download_pdf', 'Download PDF'),
|
| 291 |
-
data=pdf_buffer,
|
| 292 |
-
file_name="semantic_analysis.pdf",
|
| 293 |
-
mime="application/pdf",
|
| 294 |
-
key=f"semantic_download_{st.session_state.semantic_analysis_counter}"
|
| 295 |
-
)
|
| 296 |
-
'''
|
|
|
|
| 52 |
key=f"semantic_file_uploader_{st.session_state.semantic_state['analysis_count']}"
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# 2.1 Verificar si hay un archivo cargado y un análisis pendiente
|
| 56 |
if uploaded_file is not None and st.session_state.semantic_state.get('pending_analysis', False):
|
| 57 |
try:
|
| 58 |
with st.spinner(semantic_t.get('processing', 'Processing...')):
|
|
|
|
| 124 |
# Mostrar mensaje sobre el análisis actual
|
| 125 |
st.info(
|
| 126 |
semantic_t.get('current_analysis_message',
|
| 127 |
+
'Mostrando análisis del archivo: {}. Para realizar un nuevo análisis, cargue otro archivo.'
|
| 128 |
+
).format(st.session_state.semantic_state["current_file"])
|
| 129 |
)
|
| 130 |
+
|
| 131 |
display_semantic_results(
|
| 132 |
st.session_state.semantic_result,
|
| 133 |
lang_code,
|
|
|
|
| 204 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 205 |
|
| 206 |
# Gráfico de conceptos
|
| 207 |
+
# st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
| 208 |
+
#Colocar aquí el bloque de código
|
| 209 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 210 |
try:
|
| 211 |
# Container para el grafo con estilos mejorados
|
|
|
|
| 228 |
""",
|
| 229 |
unsafe_allow_html=True
|
| 230 |
)
|
| 231 |
+
#Colocar aquí el bloque de código
|
| 232 |
|
| 233 |
with st.container():
|
| 234 |
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
|
|
|
| 242 |
)
|
| 243 |
|
| 244 |
# Leyenda del grafo
|
| 245 |
+
#st.caption(semantic_t.get(
|
| 246 |
+
# 'graph_description',
|
| 247 |
+
# 'Visualización de relaciones entre conceptos clave identificados en el texto.'
|
| 248 |
+
#))
|
| 249 |
|
| 250 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 251 |
|
| 252 |
+
# Expandible con la interpretación
|
| 253 |
+
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación del gráfico semántico")):
|
| 254 |
+
st.markdown(f"""
|
| 255 |
+
- 🔀 {semantic_t.get('semantic_arrow_meaning', 'Las flechas indican la dirección de la relación entre conceptos')}
|
| 256 |
+
- 🎨 {semantic_t.get('semantic_color_meaning', 'Los colores más intensos indican conceptos más centrales en el texto')}
|
| 257 |
+
- ⭕ {semantic_t.get('semantic_size_meaning', 'El tamaño de los nodos representa la frecuencia del concepto')}
|
| 258 |
+
- ↔️ {semantic_t.get('semantic_thickness_meaning', 'El grosor de las líneas indica la fuerza de la conexión')}
|
| 259 |
+
""")
|
| 260 |
+
|
| 261 |
# Contenedor para botones
|
| 262 |
col1, col2 = st.columns([1,4])
|
| 263 |
with col1:
|
| 264 |
st.download_button(
|
| 265 |
+
label="📥 " + semantic_t.get('download_semantic_network_graph', "Descargar gráfico de red semántica"),
|
| 266 |
data=graph_bytes,
|
| 267 |
file_name="semantic_graph.png",
|
| 268 |
mime="image/png",
|
| 269 |
use_container_width=True
|
| 270 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
except Exception as e:
|
| 273 |
logger.error(f"Error displaying graph: {str(e)}")
|
| 274 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
| 275 |
else:
|
| 276 |
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|