Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
@@ -145,6 +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 |
"""
|
149 |
if semantic_result is None or not semantic_result['success']:
|
150 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
@@ -152,10 +153,9 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
152 |
|
153 |
analysis = semantic_result['analysis']
|
154 |
|
155 |
-
# Mostrar conceptos clave
|
156 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
157 |
if 'key_concepts' in analysis and analysis['key_concepts']:
|
158 |
-
# Crear tabla de conceptos
|
159 |
df = pd.DataFrame(
|
160 |
analysis['key_concepts'],
|
161 |
columns=[
|
@@ -164,113 +164,57 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
164 |
]
|
165 |
)
|
166 |
|
167 |
-
#
|
168 |
-
st.
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
font-weight: bold;
|
187 |
-
}
|
188 |
-
.concept-freq {
|
189 |
-
color: #666;
|
190 |
-
font-size: 0.9em;
|
191 |
-
}
|
192 |
-
</style>
|
193 |
-
<div class="concept-table">
|
194 |
-
""" +
|
195 |
-
''.join([
|
196 |
-
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
197 |
-
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
198 |
-
for concept, freq in df.values
|
199 |
-
]) +
|
200 |
-
"</div>",
|
201 |
-
unsafe_allow_html=True
|
202 |
-
)
|
203 |
else:
|
204 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
205 |
|
206 |
-
#
|
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 |
-
#
|
212 |
-
st.
|
213 |
-
|
214 |
-
|
215 |
-
.
|
216 |
-
background-color: white;
|
217 |
-
border-radius: 10px;
|
218 |
-
padding: 20px;
|
219 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
220 |
-
margin: 10px 0;
|
221 |
-
}
|
222 |
-
.button-container {
|
223 |
-
display: flex;
|
224 |
-
gap: 10px;
|
225 |
-
margin: 10px 0;
|
226 |
-
}
|
227 |
-
</style>
|
228 |
-
""",
|
229 |
-
unsafe_allow_html=True
|
230 |
)
|
231 |
-
#Colocar aquí el bloque de código
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
f'<img src="data:image/png;base64,{graph_base64}" alt="Concept Graph" style="width:100%;"/>',
|
241 |
-
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 |
-
#
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
use_container_width=True
|
270 |
-
)
|
271 |
-
|
272 |
except Exception as e:
|
273 |
-
logger.error(f"Error
|
274 |
-
st.error(semantic_t.get('graph_error', 'Error
|
275 |
else:
|
276 |
-
st.info(semantic_t.get('no_graph', 'No
|
|
|
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 simplificada que muestra el gráfico directamente.
|
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
|
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=[
|
|
|
164 |
]
|
165 |
)
|
166 |
|
167 |
+
# Mostrar conceptos como chips
|
168 |
+
cols = st.columns(4) # 4 columnas para distribuir los conceptos
|
169 |
+
for i, (concept, freq) in enumerate(df.values):
|
170 |
+
with cols[i % 4]:
|
171 |
+
st.markdown(
|
172 |
+
f"""
|
173 |
+
<div style="
|
174 |
+
background-color: #f0f2f6;
|
175 |
+
border-radius: 20px;
|
176 |
+
padding: 8px 12px;
|
177 |
+
margin: 5px 0;
|
178 |
+
text-align: center;
|
179 |
+
">
|
180 |
+
<b>{concept}</b><br>
|
181 |
+
<small>{freq:.2f}</small>
|
182 |
+
</div>
|
183 |
+
""",
|
184 |
+
unsafe_allow_html=True
|
185 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
else:
|
187 |
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
188 |
|
189 |
+
# Mostrar gráfico de conceptos directamente
|
|
|
|
|
190 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
191 |
try:
|
192 |
+
# Mostrar el gráfico directamente con st.image()
|
193 |
+
st.image(
|
194 |
+
analysis['concept_graph'],
|
195 |
+
use_column_width=True,
|
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 del gráfico")):
|
201 |
+
st.markdown(f"""
|
202 |
+
- 🔀 {semantic_t.get('semantic_arrow_meaning', 'Flechas: dirección de la relación')}
|
203 |
+
- 🎨 {semantic_t.get('semantic_color_meaning', 'Color: centralidad del concepto')}
|
204 |
+
- ⭕ {semantic_t.get('semantic_size_meaning', 'Tamaño: frecuencia del concepto')}
|
205 |
+
- ↔️ {semantic_t.get('semantic_thickness_meaning', 'Grosor: fuerza de la conexión')}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
""")
|
207 |
|
208 |
+
# Botón de descarga
|
209 |
+
st.download_button(
|
210 |
+
label="📥 " + semantic_t.get('download_graph', "Descargar gráfico"),
|
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'))
|