Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
@@ -97,10 +97,9 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
97 |
):
|
98 |
st.success(semantic_t.get('success_message', 'Analysis saved successfully'))
|
99 |
|
100 |
-
# 4.6 Mostrar resultados
|
101 |
display_semantic_results(
|
102 |
-
st.session_state.semantic_result,
|
103 |
-
analysis_result,
|
104 |
lang_code,
|
105 |
semantic_t
|
106 |
)
|
@@ -127,15 +126,21 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
127 |
st.error("Se produjo un error. Por favor, intente de nuevo.")
|
128 |
|
129 |
#######################################
|
130 |
-
def display_semantic_results(
|
131 |
"""
|
132 |
Muestra los resultados del análisis semántico en tabs
|
|
|
|
|
|
|
|
|
133 |
"""
|
134 |
-
|
|
|
135 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
136 |
return
|
137 |
-
|
138 |
-
|
|
|
139 |
|
140 |
# Crear tabs para los resultados
|
141 |
tab1, tab2 = st.tabs([
|
@@ -150,16 +155,22 @@ def display_semantic_results(result, lang_code, semantic_t):
|
|
150 |
# Columna 1: Lista de conceptos
|
151 |
with col1:
|
152 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
158 |
|
159 |
# Columna 2: Gráfico de conceptos
|
160 |
with col2:
|
161 |
st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
162 |
-
|
|
|
|
|
|
|
163 |
|
164 |
# Tab 2: Entidades
|
165 |
with tab2:
|
@@ -172,25 +183,31 @@ def display_semantic_results(result, lang_code, semantic_t):
|
|
172 |
for entity_type, entities in analysis['entities'].items():
|
173 |
st.markdown(f"**{entity_type}**")
|
174 |
st.markdown("• " + "\n• ".join(entities))
|
|
|
|
|
175 |
|
176 |
# Columna 2: Gráfico de entidades
|
177 |
with col2:
|
178 |
st.subheader(semantic_t.get('entity_graph', 'Entities Graph'))
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
181 |
# Botón de exportación al final
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
97 |
):
|
98 |
st.success(semantic_t.get('success_message', 'Analysis saved successfully'))
|
99 |
|
100 |
+
# 4.6 Mostrar resultados - CORREGIDO: removido analysis_result redundante
|
101 |
display_semantic_results(
|
102 |
+
st.session_state.semantic_result,
|
|
|
103 |
lang_code,
|
104 |
semantic_t
|
105 |
)
|
|
|
126 |
st.error("Se produjo un error. Por favor, intente de nuevo.")
|
127 |
|
128 |
#######################################
|
129 |
+
def display_semantic_results(semantic_result, lang_code, semantic_t):
|
130 |
"""
|
131 |
Muestra los resultados del análisis semántico en tabs
|
132 |
+
Args:
|
133 |
+
semantic_result: Diccionario con los resultados del análisis
|
134 |
+
lang_code: Código del idioma actual
|
135 |
+
semantic_t: Diccionario de traducciones semánticas
|
136 |
"""
|
137 |
+
# Verificar resultado usando el nombre correcto de la variable
|
138 |
+
if semantic_result is None or not semantic_result['success']:
|
139 |
st.warning(semantic_t.get('no_results', 'No results available'))
|
140 |
return
|
141 |
+
|
142 |
+
# Usar semantic_result en lugar de result
|
143 |
+
analysis = semantic_result['analysis']
|
144 |
|
145 |
# Crear tabs para los resultados
|
146 |
tab1, tab2 = st.tabs([
|
|
|
155 |
# Columna 1: Lista de conceptos
|
156 |
with col1:
|
157 |
st.subheader(semantic_t.get('key_concepts', 'Key Concepts'))
|
158 |
+
if 'key_concepts' in analysis:
|
159 |
+
concept_text = "\n".join([
|
160 |
+
f"• {concept} ({frequency:.2f})"
|
161 |
+
for concept, frequency in analysis['key_concepts']
|
162 |
+
])
|
163 |
+
st.markdown(concept_text)
|
164 |
+
else:
|
165 |
+
st.info(semantic_t.get('no_concepts', 'No key concepts found'))
|
166 |
|
167 |
# Columna 2: Gráfico de conceptos
|
168 |
with col2:
|
169 |
st.subheader(semantic_t.get('concept_graph', 'Concepts Graph'))
|
170 |
+
if 'concept_graph' in analysis:
|
171 |
+
st.image(analysis['concept_graph'])
|
172 |
+
else:
|
173 |
+
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
174 |
|
175 |
# Tab 2: Entidades
|
176 |
with tab2:
|
|
|
183 |
for entity_type, entities in analysis['entities'].items():
|
184 |
st.markdown(f"**{entity_type}**")
|
185 |
st.markdown("• " + "\n• ".join(entities))
|
186 |
+
else:
|
187 |
+
st.info(semantic_t.get('no_entities', 'No entities found'))
|
188 |
|
189 |
# Columna 2: Gráfico de entidades
|
190 |
with col2:
|
191 |
st.subheader(semantic_t.get('entity_graph', 'Entities Graph'))
|
192 |
+
if 'entity_graph' in analysis:
|
193 |
+
st.image(analysis['entity_graph'])
|
194 |
+
else:
|
195 |
+
st.info(semantic_t.get('no_entity_graph', 'No entity graph available'))
|
196 |
+
|
197 |
# Botón de exportación al final
|
198 |
+
if 'semantic_analysis_counter' in st.session_state:
|
199 |
+
col1, col2, col3 = st.columns([2,1,2])
|
200 |
+
with col2:
|
201 |
+
if st.button(
|
202 |
+
semantic_t.get('export_button', 'Export Analysis'),
|
203 |
+
key=f"semantic_export_{st.session_state.semantic_analysis_counter}",
|
204 |
+
use_container_width=True
|
205 |
+
):
|
206 |
+
pdf_buffer = export_user_interactions(st.session_state.username, 'semantic')
|
207 |
+
st.download_button(
|
208 |
+
label=semantic_t.get('download_pdf', 'Download PDF'),
|
209 |
+
data=pdf_buffer,
|
210 |
+
file_name="semantic_analysis.pdf",
|
211 |
+
mime="application/pdf",
|
212 |
+
key=f"semantic_download_{st.session_state.semantic_analysis_counter}"
|
213 |
+
)
|