Update modules/discourse/discourse_interface.py
Browse files
modules/discourse/discourse_interface.py
CHANGED
@@ -125,6 +125,9 @@ def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
|
125 |
logger.error(f"Error general en interfaz del discurso: {str(e)}")
|
126 |
st.error(discourse_t.get('general_error', 'Se produjo un error. Por favor, intente de nuevo.'))
|
127 |
|
|
|
|
|
|
|
128 |
def display_discourse_results(result, lang_code, discourse_t):
|
129 |
"""
|
130 |
Muestra los resultados del análisis del discurso
|
@@ -133,6 +136,49 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
133 |
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
134 |
return
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
col1, col2 = st.columns(2)
|
137 |
|
138 |
# Documento 1
|
@@ -140,12 +186,43 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
140 |
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
|
141 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
142 |
if 'key_concepts1' in result:
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
if 'graph1' in result:
|
148 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
else:
|
150 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
151 |
else:
|
@@ -156,12 +233,43 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
156 |
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
|
157 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
158 |
if 'key_concepts2' in result:
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
if 'graph2' in result:
|
164 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
else:
|
166 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
167 |
else:
|
|
|
125 |
logger.error(f"Error general en interfaz del discurso: {str(e)}")
|
126 |
st.error(discourse_t.get('general_error', 'Se produjo un error. Por favor, intente de nuevo.'))
|
127 |
|
128 |
+
|
129 |
+
|
130 |
+
#####################################################################################################################
|
131 |
def display_discourse_results(result, lang_code, discourse_t):
|
132 |
"""
|
133 |
Muestra los resultados del análisis del discurso
|
|
|
136 |
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
137 |
return
|
138 |
|
139 |
+
# Estilo CSS
|
140 |
+
st.markdown("""
|
141 |
+
<style>
|
142 |
+
.concepts-container {
|
143 |
+
display: flex;
|
144 |
+
flex-wrap: nowrap;
|
145 |
+
gap: 8px;
|
146 |
+
padding: 12px;
|
147 |
+
background-color: #f8f9fa;
|
148 |
+
border-radius: 8px;
|
149 |
+
overflow-x: auto;
|
150 |
+
margin-bottom: 15px;
|
151 |
+
white-space: nowrap;
|
152 |
+
}
|
153 |
+
.concept-item {
|
154 |
+
background-color: white;
|
155 |
+
border-radius: 4px;
|
156 |
+
padding: 6px 10px;
|
157 |
+
display: inline-flex;
|
158 |
+
align-items: center;
|
159 |
+
gap: 4px;
|
160 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
161 |
+
flex-shrink: 0;
|
162 |
+
}
|
163 |
+
.concept-name {
|
164 |
+
font-weight: 500;
|
165 |
+
color: #1f2937;
|
166 |
+
font-size: 0.85em;
|
167 |
+
}
|
168 |
+
.concept-freq {
|
169 |
+
color: #6b7280;
|
170 |
+
font-size: 0.75em;
|
171 |
+
}
|
172 |
+
.graph-container {
|
173 |
+
background-color: white;
|
174 |
+
padding: 15px;
|
175 |
+
border-radius: 8px;
|
176 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
177 |
+
margin-top: 10px;
|
178 |
+
}
|
179 |
+
</style>
|
180 |
+
""", unsafe_allow_html=True)
|
181 |
+
|
182 |
col1, col2 = st.columns(2)
|
183 |
|
184 |
# Documento 1
|
|
|
186 |
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
|
187 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
188 |
if 'key_concepts1' in result:
|
189 |
+
concepts_html = f"""
|
190 |
+
<div class="concepts-container">
|
191 |
+
{''.join([
|
192 |
+
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
193 |
+
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
194 |
+
for concept, freq in result['key_concepts1']
|
195 |
+
])}
|
196 |
+
</div>
|
197 |
+
"""
|
198 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
199 |
|
200 |
if 'graph1' in result:
|
201 |
+
with st.container():
|
202 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
203 |
+
st.pyplot(result['graph1'])
|
204 |
+
|
205 |
+
# Botones y controles
|
206 |
+
button_col1, spacer_col1 = st.columns([1,4])
|
207 |
+
with button_col1:
|
208 |
+
if 'graph1_bytes' in result:
|
209 |
+
st.download_button(
|
210 |
+
label="📥 " + discourse_t.get('download_graph', "Download"),
|
211 |
+
data=result['graph1_bytes'],
|
212 |
+
file_name="discourse_graph1.png",
|
213 |
+
mime="image/png",
|
214 |
+
use_container_width=True
|
215 |
+
)
|
216 |
+
|
217 |
+
with st.expander("📊 " + discourse_t.get('graph_help', "Graph Interpretation")):
|
218 |
+
st.markdown("""
|
219 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
220 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
221 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
222 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
223 |
+
""")
|
224 |
+
|
225 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
226 |
else:
|
227 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
228 |
else:
|
|
|
233 |
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
|
234 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
235 |
if 'key_concepts2' in result:
|
236 |
+
concepts_html = f"""
|
237 |
+
<div class="concepts-container">
|
238 |
+
{''.join([
|
239 |
+
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
240 |
+
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
241 |
+
for concept, freq in result['key_concepts2']
|
242 |
+
])}
|
243 |
+
</div>
|
244 |
+
"""
|
245 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
246 |
|
247 |
if 'graph2' in result:
|
248 |
+
with st.container():
|
249 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
250 |
+
st.pyplot(result['graph2'])
|
251 |
+
|
252 |
+
# Botones y controles
|
253 |
+
button_col2, spacer_col2 = st.columns([1,4])
|
254 |
+
with button_col2:
|
255 |
+
if 'graph2_bytes' in result:
|
256 |
+
st.download_button(
|
257 |
+
label="📥 " + discourse_t.get('download_graph', "Download"),
|
258 |
+
data=result['graph2_bytes'],
|
259 |
+
file_name="discourse_graph2.png",
|
260 |
+
mime="image/png",
|
261 |
+
use_container_width=True
|
262 |
+
)
|
263 |
+
|
264 |
+
with st.expander("📊 " + discourse_t.get('graph_help', "Graph Interpretation")):
|
265 |
+
st.markdown("""
|
266 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
267 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
268 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
269 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
270 |
+
""")
|
271 |
+
|
272 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
273 |
else:
|
274 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
275 |
else:
|