Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
@@ -151,7 +151,7 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
151 |
analysis = semantic_result['analysis']
|
152 |
|
153 |
# Crear contenedor para los resultados con proporciones ajustadas
|
154 |
-
col1, col2 = st.columns([1, 2])
|
155 |
|
156 |
# Columna 1: Lista de conceptos clave
|
157 |
with col1:
|
@@ -159,7 +159,7 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
159 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
160 |
# Crear tabla de conceptos
|
161 |
df = pd.DataFrame(
|
162 |
-
analysis['key_concepts'],
|
163 |
columns=[
|
164 |
semantic_t.get('concept', 'Concept'),
|
165 |
semantic_t.get('frequency', 'Frequency')
|
@@ -173,7 +173,7 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
173 |
format="%.2f"
|
174 |
)
|
175 |
},
|
176 |
-
height=400
|
177 |
)
|
178 |
else:
|
179 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
@@ -182,23 +182,80 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
182 |
with col2:
|
183 |
st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
184 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
else:
|
200 |
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
'''
|
203 |
# Bot贸n de exportaci贸n al final
|
204 |
if 'semantic_analysis_counter' in st.session_state:
|
|
|
151 |
analysis = semantic_result['analysis']
|
152 |
|
153 |
# Crear contenedor para los resultados con proporciones ajustadas
|
154 |
+
col1, col2 = st.columns([1, 2])
|
155 |
|
156 |
# Columna 1: Lista de conceptos clave
|
157 |
with col1:
|
|
|
159 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
160 |
# Crear tabla de conceptos
|
161 |
df = pd.DataFrame(
|
162 |
+
analysis['key_concepts'],
|
163 |
columns=[
|
164 |
semantic_t.get('concept', 'Concept'),
|
165 |
semantic_t.get('frequency', 'Frequency')
|
|
|
173 |
format="%.2f"
|
174 |
)
|
175 |
},
|
176 |
+
height=400
|
177 |
)
|
178 |
else:
|
179 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
|
|
182 |
with col2:
|
183 |
st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
184 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
185 |
+
try:
|
186 |
+
# Configurar el estilo de la visualizaci贸n
|
187 |
+
st.markdown(
|
188 |
+
"""
|
189 |
+
<style>
|
190 |
+
.semantic-graph-container {
|
191 |
+
background-color: white;
|
192 |
+
border-radius: 10px;
|
193 |
+
padding: 20px;
|
194 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
195 |
+
margin: 10px 0;
|
196 |
+
}
|
197 |
+
.stImage {
|
198 |
+
display: flex;
|
199 |
+
justify-content: center;
|
200 |
+
align-items: center;
|
201 |
+
}
|
202 |
+
.stImage > img {
|
203 |
+
max-width: 100%;
|
204 |
+
height: auto;
|
205 |
+
object-fit: contain;
|
206 |
+
}
|
207 |
+
</style>
|
208 |
+
""",
|
209 |
+
unsafe_allow_html=True
|
210 |
+
)
|
211 |
+
|
212 |
+
# Crear contenedor para el grafo
|
213 |
+
with st.container():
|
214 |
+
st.markdown('<div class="semantic-graph-container">', unsafe_allow_html=True)
|
215 |
+
|
216 |
+
# Convertir los bytes de la imagen a formato base64
|
217 |
+
graph_bytes = analysis['concept_graph']
|
218 |
+
graph_base64 = base64.b64encode(graph_bytes).decode()
|
219 |
+
|
220 |
+
# Mostrar la imagen con HTML para mayor control
|
221 |
+
st.markdown(
|
222 |
+
f'<img src="data:image/png;base64,{graph_base64}" alt="Concept Graph" style="width:100%;"/>',
|
223 |
+
unsafe_allow_html=True
|
224 |
+
)
|
225 |
+
|
226 |
+
# Agregar leyenda o descripci贸n si es necesario
|
227 |
+
st.caption(semantic_t.get(
|
228 |
+
'graph_description',
|
229 |
+
'El grosor de las l铆neas indica la fuerza de la relaci贸n. '
|
230 |
+
'Los colores indican la centralidad del concepto.'
|
231 |
+
))
|
232 |
+
|
233 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
234 |
+
|
235 |
+
# Agregar bot贸n de descarga
|
236 |
+
st.download_button(
|
237 |
+
label=semantic_t.get('download_graph', "Download Graph"),
|
238 |
+
data=graph_bytes,
|
239 |
+
file_name="semantic_graph.png",
|
240 |
+
mime="image/png",
|
241 |
+
)
|
242 |
+
|
243 |
+
except Exception as e:
|
244 |
+
logger.error(f"Error displaying graph: {str(e)}")
|
245 |
+
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
246 |
else:
|
247 |
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
248 |
|
249 |
+
# A帽adir informaci贸n adicional sobre la interpretaci贸n del grafo
|
250 |
+
with st.expander(semantic_t.get('graph_help', "How to interpret this graph")):
|
251 |
+
st.markdown("""
|
252 |
+
- Las flechas indican la direcci贸n de la relaci贸n entre conceptos
|
253 |
+
- Los colores m谩s intensos indican conceptos m谩s centrales en el texto
|
254 |
+
- El tama帽o de los nodos representa la frecuencia del concepto
|
255 |
+
- El grosor de las l铆neas indica la fuerza de la conexi贸n
|
256 |
+
""")
|
257 |
+
|
258 |
+
########################################################################################
|
259 |
'''
|
260 |
# Bot贸n de exportaci贸n al final
|
261 |
if 'semantic_analysis_counter' in st.session_state:
|