Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
|
@@ -142,10 +142,10 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 142 |
|
| 143 |
|
| 144 |
#######################################
|
|
|
|
| 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 sin div contenedor del gráfico.
|
| 149 |
"""
|
| 150 |
if semantic_result is None or not semantic_result['success']:
|
| 151 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
|
@@ -153,66 +153,98 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 153 |
|
| 154 |
analysis = semantic_result['analysis']
|
| 155 |
|
| 156 |
-
# Mostrar conceptos clave en formato horizontal
|
| 157 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
| 158 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
else:
|
| 184 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 185 |
|
| 186 |
-
#
|
| 187 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 188 |
try:
|
| 189 |
-
#
|
| 190 |
st.image(
|
| 191 |
analysis['concept_graph'],
|
| 192 |
-
use_container_width=True
|
| 193 |
-
caption=semantic_t.get('graph_description', 'Visualización de relaciones entre conceptos clave')
|
| 194 |
)
|
| 195 |
|
| 196 |
-
#
|
| 197 |
-
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación")):
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
""")
|
| 204 |
|
| 205 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
st.download_button(
|
| 207 |
-
label="📥 " + semantic_t.get('
|
| 208 |
data=analysis['concept_graph'],
|
| 209 |
-
file_name="
|
| 210 |
mime="image/png",
|
| 211 |
use_container_width=True
|
| 212 |
)
|
| 213 |
|
|
|
|
|
|
|
| 214 |
except Exception as e:
|
| 215 |
-
logger.error(f"Error
|
| 216 |
-
st.error(semantic_t.get('graph_error', 'Error
|
| 217 |
else:
|
| 218 |
-
st.info(semantic_t.get('no_graph', 'No
|
|
|
|
|
|
| 142 |
|
| 143 |
|
| 144 |
#######################################
|
| 145 |
+
|
| 146 |
def display_semantic_results(semantic_result, lang_code, semantic_t):
|
| 147 |
"""
|
| 148 |
Muestra los resultados del análisis semántico de conceptos clave.
|
|
|
|
| 149 |
"""
|
| 150 |
if semantic_result is None or not semantic_result['success']:
|
| 151 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
|
|
|
| 153 |
|
| 154 |
analysis = semantic_result['analysis']
|
| 155 |
|
| 156 |
+
# Mostrar conceptos clave en formato horizontal (se mantiene igual)
|
| 157 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
| 158 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
| 159 |
+
df = pd.DataFrame(
|
| 160 |
+
analysis['key_concepts'],
|
| 161 |
+
columns=[
|
| 162 |
+
semantic_t.get('concept', 'Concept'),
|
| 163 |
+
semantic_t.get('frequency', 'Frequency')
|
| 164 |
+
]
|
| 165 |
+
)
|
| 166 |
|
| 167 |
+
st.write(
|
| 168 |
+
"""
|
| 169 |
+
<style>
|
| 170 |
+
.concept-table {
|
| 171 |
+
display: flex;
|
| 172 |
+
flex-wrap: wrap;
|
| 173 |
+
gap: 10px;
|
| 174 |
+
margin-bottom: 20px;
|
| 175 |
+
}
|
| 176 |
+
.concept-item {
|
| 177 |
+
background-color: #f0f2f6;
|
| 178 |
+
border-radius: 5px;
|
| 179 |
+
padding: 8px 12px;
|
| 180 |
+
display: flex;
|
| 181 |
+
align-items: center;
|
| 182 |
+
gap: 8px;
|
| 183 |
+
}
|
| 184 |
+
.concept-name {
|
| 185 |
+
font-weight: bold;
|
| 186 |
+
}
|
| 187 |
+
.concept-freq {
|
| 188 |
+
color: #666;
|
| 189 |
+
font-size: 0.9em;
|
| 190 |
+
}
|
| 191 |
+
</style>
|
| 192 |
+
<div class="concept-table">
|
| 193 |
+
""" +
|
| 194 |
+
''.join([
|
| 195 |
+
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
| 196 |
+
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
| 197 |
+
for concept, freq in df.values
|
| 198 |
+
]) +
|
| 199 |
+
"</div>",
|
| 200 |
+
unsafe_allow_html=True
|
| 201 |
+
)
|
| 202 |
else:
|
| 203 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
| 204 |
|
| 205 |
+
# Gráfico de conceptos (versión modificada)
|
| 206 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 207 |
try:
|
| 208 |
+
# Sección del gráfico (sin div contenedor)
|
| 209 |
st.image(
|
| 210 |
analysis['concept_graph'],
|
| 211 |
+
use_container_width=True
|
|
|
|
| 212 |
)
|
| 213 |
|
| 214 |
+
# Expandible con la interpretación (se mantiene igual)
|
| 215 |
+
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación del gráfico semántico")):
|
| 216 |
+
st.markdown(f"""
|
| 217 |
+
- 🔀 {semantic_t.get('semantic_arrow_meaning', 'Las flechas indican la dirección de la relación entre conceptos')}
|
| 218 |
+
- 🎨 {semantic_t.get('semantic_color_meaning', 'Los colores más intensos indican conceptos más centrales en el texto')}
|
| 219 |
+
- ⭕ {semantic_t.get('semantic_size_meaning', 'El tamaño de los nodos representa la frecuencia del concepto')}
|
| 220 |
+
- ↔️ {semantic_t.get('semantic_thickness_meaning', 'El grosor de las líneas indica la fuerza de la conexión')}
|
| 221 |
""")
|
| 222 |
|
| 223 |
+
# Contenedor para botones (se mantiene igual pero centrado)
|
| 224 |
+
st.markdown("""
|
| 225 |
+
<style>
|
| 226 |
+
.download-btn-container {
|
| 227 |
+
display: flex;
|
| 228 |
+
justify-content: center;
|
| 229 |
+
margin-top: 10px;
|
| 230 |
+
}
|
| 231 |
+
</style>
|
| 232 |
+
<div class="download-btn-container">
|
| 233 |
+
""", unsafe_allow_html=True)
|
| 234 |
+
|
| 235 |
st.download_button(
|
| 236 |
+
label="📥 " + semantic_t.get('download_semantic_network_graph', "Descargar gráfico de red semántica"),
|
| 237 |
data=analysis['concept_graph'],
|
| 238 |
+
file_name="semantic_graph.png",
|
| 239 |
mime="image/png",
|
| 240 |
use_container_width=True
|
| 241 |
)
|
| 242 |
|
| 243 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 244 |
+
|
| 245 |
except Exception as e:
|
| 246 |
+
logger.error(f"Error displaying graph: {str(e)}")
|
| 247 |
+
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
| 248 |
else:
|
| 249 |
+
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
| 250 |
+
|