Spaces:
Sleeping
Sleeping
Update modules/discourse/discourse_interface.py
Browse files
modules/discourse/discourse_interface.py
CHANGED
|
@@ -121,111 +121,6 @@ def display_discourse_interface(lang_code, nlp_models, discourse_t):
|
|
| 121 |
logger.error(f"Error general en interfaz discursiva: {str(e)}")
|
| 122 |
st.error(discourse_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|
| 123 |
|
| 124 |
-
def display_discourse_results(result, lang_code, discourse_t):
|
| 125 |
-
"""
|
| 126 |
-
Muestra los resultados del análisis del discurso
|
| 127 |
-
"""
|
| 128 |
-
if not result.get('success'):
|
| 129 |
-
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
| 130 |
-
return
|
| 131 |
-
|
| 132 |
-
# Estilo CSS unificado
|
| 133 |
-
st.markdown("""
|
| 134 |
-
<style>
|
| 135 |
-
.concepts-container {
|
| 136 |
-
display: flex;
|
| 137 |
-
flex-wrap: nowrap;
|
| 138 |
-
gap: 8px;
|
| 139 |
-
padding: 12px;
|
| 140 |
-
background-color: #f8f9fa;
|
| 141 |
-
border-radius: 8px;
|
| 142 |
-
overflow-x: auto;
|
| 143 |
-
margin-bottom: 15px;
|
| 144 |
-
white-space: nowrap;
|
| 145 |
-
}
|
| 146 |
-
.concept-item {
|
| 147 |
-
background-color: white;
|
| 148 |
-
border-radius: 4px;
|
| 149 |
-
padding: 6px 10px;
|
| 150 |
-
display: inline-flex;
|
| 151 |
-
align-items: center;
|
| 152 |
-
gap: 4px;
|
| 153 |
-
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
| 154 |
-
flex-shrink: 0;
|
| 155 |
-
}
|
| 156 |
-
.concept-name {
|
| 157 |
-
font-weight: 500;
|
| 158 |
-
color: #1f2937;
|
| 159 |
-
font-size: 0.85em;
|
| 160 |
-
}
|
| 161 |
-
.concept-freq {
|
| 162 |
-
color: #6b7280;
|
| 163 |
-
font-size: 0.75em;
|
| 164 |
-
}
|
| 165 |
-
.graph-section {
|
| 166 |
-
margin-top: 20px;
|
| 167 |
-
background-color: white;
|
| 168 |
-
padding: 15px;
|
| 169 |
-
border-radius: 8px;
|
| 170 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 171 |
-
}
|
| 172 |
-
</style>
|
| 173 |
-
""", unsafe_allow_html=True)
|
| 174 |
-
|
| 175 |
-
col1, col2 = st.columns(2)
|
| 176 |
-
|
| 177 |
-
for i, (concepts_key, graph_key, title) in enumerate([
|
| 178 |
-
('key_concepts1', 'graph1', 'Documento 1'),
|
| 179 |
-
('key_concepts2', 'graph2', 'Documento 2')
|
| 180 |
-
]):
|
| 181 |
-
with [col1, col2][i]:
|
| 182 |
-
st.subheader(discourse_t.get(f'doc{i+1}_title', title))
|
| 183 |
-
|
| 184 |
-
# Mostrar conceptos
|
| 185 |
-
if concepts_key in result:
|
| 186 |
-
concepts_html = f"""
|
| 187 |
-
<div class="concepts-container">
|
| 188 |
-
{''.join([
|
| 189 |
-
f'<div class="concept-item"><span class="concept-name">{concept}</span>'
|
| 190 |
-
f'<span class="concept-freq">({freq:.2f})</span></div>'
|
| 191 |
-
for concept, freq in result[concepts_key]
|
| 192 |
-
])}
|
| 193 |
-
</div>
|
| 194 |
-
"""
|
| 195 |
-
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 196 |
-
|
| 197 |
-
# Mostrar grafo
|
| 198 |
-
if graph_key in result:
|
| 199 |
-
st.markdown('<div class="graph-section">', unsafe_allow_html=True)
|
| 200 |
-
st.pyplot(result[graph_key])
|
| 201 |
-
|
| 202 |
-
# Botón de descarga
|
| 203 |
-
st.download_button(
|
| 204 |
-
label="📥 " + discourse_t.get('download_graph', "Download"),
|
| 205 |
-
data=result.get(f'{graph_key}_bytes'),
|
| 206 |
-
file_name=f"discourse_graph{i+1}.png",
|
| 207 |
-
mime="image/png",
|
| 208 |
-
use_container_width=True
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
# Interpretación del grafo
|
| 212 |
-
st.markdown("**📊 Interpretación del grafo:**")
|
| 213 |
-
st.markdown("""
|
| 214 |
-
- 🔀 Las flechas indican la dirección de la relación
|
| 215 |
-
- 🎨 Colores más intensos = conceptos más centrales
|
| 216 |
-
- ⭕ Tamaño del nodo = frecuencia del concepto
|
| 217 |
-
- ↔️ Grosor de líneas = fuerza de la conexión
|
| 218 |
-
""")
|
| 219 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 220 |
-
else:
|
| 221 |
-
st.warning(discourse_t.get('graph_not_available', 'Gráfico no disponible'))
|
| 222 |
-
else:
|
| 223 |
-
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
|
| 224 |
-
|
| 225 |
-
# Nota informativa
|
| 226 |
-
st.info(discourse_t.get('comparison_note',
|
| 227 |
-
'La funcionalidad de comparación detallada estará disponible en una próxima actualización.'))
|
| 228 |
-
|
| 229 |
##########################################################################################
|
| 230 |
|
| 231 |
def display_discourse_results(result, lang_code, discourse_t):
|
|
|
|
| 121 |
logger.error(f"Error general en interfaz discursiva: {str(e)}")
|
| 122 |
st.error(discourse_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
##########################################################################################
|
| 125 |
|
| 126 |
def display_discourse_results(result, lang_code, discourse_t):
|