Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
|
@@ -145,7 +145,7 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 145 |
def display_semantic_results(semantic_result, lang_code, semantic_t):
|
| 146 |
"""
|
| 147 |
Muestra los resultados del análisis semántico de conceptos clave.
|
| 148 |
-
Versión
|
| 149 |
"""
|
| 150 |
if semantic_result is None or not semantic_result['success']:
|
| 151 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
|
@@ -156,29 +156,27 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 156 |
# Mostrar conceptos clave
|
| 157 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
| 158 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
semantic_t.get('concept', 'Concept'),
|
| 163 |
-
semantic_t.get('frequency', 'Frequency')
|
| 164 |
-
]
|
| 165 |
-
)
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
with cols[i % 4]:
|
| 171 |
st.markdown(
|
| 172 |
f"""
|
| 173 |
<div style="
|
| 174 |
background-color: #f0f2f6;
|
| 175 |
-
border-radius:
|
| 176 |
-
padding:
|
| 177 |
-
margin:
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
| 179 |
">
|
| 180 |
-
<
|
| 181 |
-
<
|
| 182 |
</div>
|
| 183 |
""",
|
| 184 |
unsafe_allow_html=True
|
|
@@ -186,35 +184,36 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 186 |
else:
|
| 187 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 188 |
|
| 189 |
-
# Mostrar gráfico de conceptos
|
| 190 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 191 |
try:
|
| 192 |
-
# Mostrar el gráfico
|
| 193 |
st.image(
|
| 194 |
analysis['concept_graph'],
|
| 195 |
-
|
| 196 |
caption=semantic_t.get('graph_description', 'Visualización de relaciones entre conceptos clave')
|
| 197 |
)
|
| 198 |
|
| 199 |
-
# Sección de interpretación
|
| 200 |
-
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación
|
| 201 |
-
st.
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
""")
|
| 207 |
|
| 208 |
-
# Botón de descarga
|
| 209 |
st.download_button(
|
| 210 |
-
label="
|
| 211 |
data=analysis['concept_graph'],
|
| 212 |
file_name="semantic_network.png",
|
| 213 |
-
mime="image/png"
|
|
|
|
| 214 |
)
|
| 215 |
|
| 216 |
except Exception as e:
|
| 217 |
logger.error(f"Error al mostrar el gráfico: {str(e)}")
|
| 218 |
st.error(semantic_t.get('graph_error', 'Error al visualizar el gráfico'))
|
| 219 |
else:
|
| 220 |
-
st.info(semantic_t.get('no_graph', 'No se generó el gráfico de conceptos'))
|
|
|
|
| 145 |
def display_semantic_results(semantic_result, lang_code, semantic_t):
|
| 146 |
"""
|
| 147 |
Muestra los resultados del análisis semántico de conceptos clave.
|
| 148 |
+
Versión optimizada con distribución uniforme de conceptos y formato compacto.
|
| 149 |
"""
|
| 150 |
if semantic_result is None or not semantic_result['success']:
|
| 151 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
|
|
|
| 156 |
# Mostrar conceptos clave
|
| 157 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
| 158 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
| 159 |
+
# Calcular número óptimo de columnas (máx 5, mín 2)
|
| 160 |
+
num_concepts = len(analysis['key_concepts'])
|
| 161 |
+
num_cols = min(max(2, (num_concepts + 2) // 3), 5) # Fórmula para distribución óptima
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
cols = st.columns(num_cols)
|
| 164 |
+
for idx, (concept, freq) in enumerate(analysis['key_concepts']):
|
| 165 |
+
with cols[idx % num_cols]:
|
|
|
|
| 166 |
st.markdown(
|
| 167 |
f"""
|
| 168 |
<div style="
|
| 169 |
background-color: #f0f2f6;
|
| 170 |
+
border-radius: 12px;
|
| 171 |
+
padding: 6px 10px;
|
| 172 |
+
margin: 4px 0;
|
| 173 |
+
font-size: 0.9em;
|
| 174 |
+
display: flex;
|
| 175 |
+
justify-content: space-between;
|
| 176 |
+
align-items: center;
|
| 177 |
">
|
| 178 |
+
<span style="font-weight: 500;">{concept}</span>
|
| 179 |
+
<span style="color: #666; font-size: 0.85em;">{freq:.2f}</span>
|
| 180 |
</div>
|
| 181 |
""",
|
| 182 |
unsafe_allow_html=True
|
|
|
|
| 184 |
else:
|
| 185 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 186 |
|
| 187 |
+
# Mostrar gráfico de conceptos
|
| 188 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 189 |
try:
|
| 190 |
+
# Mostrar el gráfico con ancho de contenedor
|
| 191 |
st.image(
|
| 192 |
analysis['concept_graph'],
|
| 193 |
+
use_container_width=True, # Corregido el parámetro obsoleto
|
| 194 |
caption=semantic_t.get('graph_description', 'Visualización de relaciones entre conceptos clave')
|
| 195 |
)
|
| 196 |
|
| 197 |
+
# Sección de interpretación compacta
|
| 198 |
+
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación")):
|
| 199 |
+
st.caption(f"""
|
| 200 |
+
• {semantic_t.get('semantic_arrow_meaning', 'Flechas → Dirección relación')}
|
| 201 |
+
• {semantic_t.get('semantic_color_meaning', 'Color → Centralidad')}
|
| 202 |
+
• {semantic_t.get('semantic_size_meaning', 'Tamaño → Frecuencia')}
|
| 203 |
+
• {semantic_t.get('semantic_thickness_meaning', 'Grosor → Fuerza conexión')}
|
| 204 |
""")
|
| 205 |
|
| 206 |
+
# Botón de descarga compacto
|
| 207 |
st.download_button(
|
| 208 |
+
label="⬇️ " + semantic_t.get('download_graph', "Descargar"),
|
| 209 |
data=analysis['concept_graph'],
|
| 210 |
file_name="semantic_network.png",
|
| 211 |
+
mime="image/png",
|
| 212 |
+
use_container_width=True
|
| 213 |
)
|
| 214 |
|
| 215 |
except Exception as e:
|
| 216 |
logger.error(f"Error al mostrar el gráfico: {str(e)}")
|
| 217 |
st.error(semantic_t.get('graph_error', 'Error al visualizar el gráfico'))
|
| 218 |
else:
|
| 219 |
+
st.info(semantic_t.get('no_graph', 'No se generó el gráfico de conceptos'))
|