Spaces:
Running
Running
Update modules/discourse/discourse_interface.py
Browse files
modules/discourse/discourse_interface.py
CHANGED
|
@@ -154,12 +154,13 @@ def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
|
| 154 |
def display_discourse_results(result, lang_code, discourse_t):
|
| 155 |
"""
|
| 156 |
Muestra los resultados del análisis del discurso con conceptos en formato horizontal
|
|
|
|
| 157 |
"""
|
| 158 |
if not result.get('success'):
|
| 159 |
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
| 160 |
return
|
| 161 |
|
| 162 |
-
# Estilo CSS
|
| 163 |
st.markdown("""
|
| 164 |
<style>
|
| 165 |
.concepts-container {
|
|
@@ -168,9 +169,9 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 168 |
gap: 8px;
|
| 169 |
padding: 12px;
|
| 170 |
background-color: #f8f9fa;
|
| 171 |
-
border-radius: 8px;
|
| 172 |
overflow-x: auto;
|
| 173 |
-
margin-bottom:
|
| 174 |
white-space: nowrap;
|
| 175 |
}
|
| 176 |
.concept-item {
|
|
@@ -182,7 +183,6 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 182 |
gap: 4px;
|
| 183 |
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
| 184 |
flex-shrink: 0;
|
| 185 |
-
min-width: fit-content;
|
| 186 |
}
|
| 187 |
.concept-name {
|
| 188 |
font-weight: 500;
|
|
@@ -195,9 +195,14 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 195 |
}
|
| 196 |
.graph-container {
|
| 197 |
background-color: white;
|
| 198 |
-
border-radius: 8px;
|
| 199 |
-
padding:
|
| 200 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
margin-top: 10px;
|
| 202 |
}
|
| 203 |
</style>
|
|
@@ -210,7 +215,6 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 210 |
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
|
| 211 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
| 212 |
if 'key_concepts1' in result:
|
| 213 |
-
# Crear HTML para conceptos horizontales de manera más compacta
|
| 214 |
concepts_html = f"""
|
| 215 |
<div class="concepts-container">
|
| 216 |
{''.join([
|
|
@@ -222,11 +226,31 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 222 |
"""
|
| 223 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 224 |
|
| 225 |
-
# Mostrar grafo
|
| 226 |
if 'graph1' in result:
|
| 227 |
-
st.
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
else:
|
| 231 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
| 232 |
else:
|
|
@@ -237,7 +261,6 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 237 |
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
|
| 238 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
| 239 |
if 'key_concepts2' in result:
|
| 240 |
-
# Crear HTML para conceptos horizontales de manera más compacta
|
| 241 |
concepts_html = f"""
|
| 242 |
<div class="concepts-container">
|
| 243 |
{''.join([
|
|
@@ -249,11 +272,31 @@ def display_discourse_results(result, lang_code, discourse_t):
|
|
| 249 |
"""
|
| 250 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 251 |
|
| 252 |
-
# Mostrar grafo
|
| 253 |
if 'graph2' in result:
|
| 254 |
-
st.
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
else:
|
| 258 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
| 259 |
else:
|
|
|
|
| 154 |
def display_discourse_results(result, lang_code, discourse_t):
|
| 155 |
"""
|
| 156 |
Muestra los resultados del análisis del discurso con conceptos en formato horizontal
|
| 157 |
+
y botones de control consistentes
|
| 158 |
"""
|
| 159 |
if not result.get('success'):
|
| 160 |
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
| 161 |
return
|
| 162 |
|
| 163 |
+
# Estilo CSS unificado
|
| 164 |
st.markdown("""
|
| 165 |
<style>
|
| 166 |
.concepts-container {
|
|
|
|
| 169 |
gap: 8px;
|
| 170 |
padding: 12px;
|
| 171 |
background-color: #f8f9fa;
|
| 172 |
+
border-radius: 8px 8px 0 0;
|
| 173 |
overflow-x: auto;
|
| 174 |
+
margin-bottom: 0;
|
| 175 |
white-space: nowrap;
|
| 176 |
}
|
| 177 |
.concept-item {
|
|
|
|
| 183 |
gap: 4px;
|
| 184 |
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
| 185 |
flex-shrink: 0;
|
|
|
|
| 186 |
}
|
| 187 |
.concept-name {
|
| 188 |
font-weight: 500;
|
|
|
|
| 195 |
}
|
| 196 |
.graph-container {
|
| 197 |
background-color: white;
|
| 198 |
+
border-radius: 0 0 8px 8px;
|
| 199 |
+
padding: 20px;
|
| 200 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 201 |
+
margin-top: 0;
|
| 202 |
+
}
|
| 203 |
+
.controls-container {
|
| 204 |
+
display: flex;
|
| 205 |
+
gap: 10px;
|
| 206 |
margin-top: 10px;
|
| 207 |
}
|
| 208 |
</style>
|
|
|
|
| 215 |
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
|
| 216 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
| 217 |
if 'key_concepts1' in result:
|
|
|
|
| 218 |
concepts_html = f"""
|
| 219 |
<div class="concepts-container">
|
| 220 |
{''.join([
|
|
|
|
| 226 |
"""
|
| 227 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 228 |
|
|
|
|
| 229 |
if 'graph1' in result:
|
| 230 |
+
with st.container():
|
| 231 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 232 |
+
st.pyplot(result['graph1'])
|
| 233 |
+
|
| 234 |
+
# Añadir botones de control para el grafo 1
|
| 235 |
+
button_col1, spacer_col1 = st.columns([1,4])
|
| 236 |
+
with button_col1:
|
| 237 |
+
st.download_button(
|
| 238 |
+
label="📥 " + discourse_t.get('download_graph', "Download"),
|
| 239 |
+
data=result['graph1_bytes'] if 'graph1_bytes' in result else None,
|
| 240 |
+
file_name="discourse_graph1.png",
|
| 241 |
+
mime="image/png",
|
| 242 |
+
use_container_width=True
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
with st.expander("📊 " + discourse_t.get('graph_help', "Graph Interpretation")):
|
| 246 |
+
st.markdown("""
|
| 247 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 248 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 249 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 250 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 251 |
+
""")
|
| 252 |
+
|
| 253 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 254 |
else:
|
| 255 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
| 256 |
else:
|
|
|
|
| 261 |
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
|
| 262 |
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
| 263 |
if 'key_concepts2' in result:
|
|
|
|
| 264 |
concepts_html = f"""
|
| 265 |
<div class="concepts-container">
|
| 266 |
{''.join([
|
|
|
|
| 272 |
"""
|
| 273 |
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 274 |
|
|
|
|
| 275 |
if 'graph2' in result:
|
| 276 |
+
with st.container():
|
| 277 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
| 278 |
+
st.pyplot(result['graph2'])
|
| 279 |
+
|
| 280 |
+
# Añadir botones de control para el grafo 2
|
| 281 |
+
button_col2, spacer_col2 = st.columns([1,4])
|
| 282 |
+
with button_col2:
|
| 283 |
+
st.download_button(
|
| 284 |
+
label="📥 " + discourse_t.get('download_graph', "Download"),
|
| 285 |
+
data=result['graph2_bytes'] if 'graph2_bytes' in result else None,
|
| 286 |
+
file_name="discourse_graph2.png",
|
| 287 |
+
mime="image/png",
|
| 288 |
+
use_container_width=True
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
with st.expander("📊 " + discourse_t.get('graph_help', "Graph Interpretation")):
|
| 292 |
+
st.markdown("""
|
| 293 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 294 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 295 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 296 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 297 |
+
""")
|
| 298 |
+
|
| 299 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 300 |
else:
|
| 301 |
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
| 302 |
else:
|