v4 / modules /discourse /discourse_interface.py
AIdeaText's picture
Update modules/discourse/discourse_interface.py
664f529 verified
raw
history blame
7.02 kB
# modules/discourse/discourse/discourse_interface.py
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
import logging
from ..utils.widget_utils import generate_unique_key
from .discourse_process import perform_discourse_analysis
from ..database.chat_mongo_db import store_chat_history
from ..database.discourse_mongo_db import store_student_discourse_result
logger = logging.getLogger(__name__)
#############################################################################################
def display_discourse_results(result, lang_code, discourse_t):
"""
Muestra los resultados del an谩lisis del discurso con conceptos en formato horizontal
"""
if not result.get('success'):
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
return
# Estilo CSS para los conceptos horizontales
st.markdown("""
<style>
.concepts-container {
display: flex;
flex-wrap: nowrap;
gap: 8px;
padding: 12px;
background-color: #f8f9fa;
border-radius: 8px;
overflow-x: auto;
margin-bottom: 15px;
}
.concept-item {
background-color: white;
border-radius: 4px;
padding: 6px 10px;
display: inline-flex;
align-items: center;
gap: 4px;
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
flex-shrink: 0;
}
.concept-name {
font-weight: 500;
color: #1f2937;
font-size: 0.85em;
}
.concept-freq {
color: #6b7280;
font-size: 0.75em;
}
.graph-container {
background-color: white;
border-radius: 8px;
padding: 15px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
margin-top: 10px;
}
</style>
""", unsafe_allow_html=True)
col1, col2 = st.columns(2)
# Documento 1
with col1:
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
if 'key_concepts1' in result:
# Crear HTML para conceptos horizontales
concepts_html = '<div class="concepts-container">'
for concept, freq in result['key_concepts1']:
concepts_html += f"""
<div class="concept-item">
<span class="concept-name">{concept}</span>
<span class="concept-freq">({freq:.2f})</span>
</div>
"""
concepts_html += '</div>'
st.markdown(concepts_html, unsafe_allow_html=True)
if 'graph1' in result:
with st.container():
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
st.pyplot(result['graph1'])
st.markdown('</div>', unsafe_allow_html=True)
else:
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
else:
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
# Documento 2
with col2:
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
if 'key_concepts2' in result:
# Crear HTML para conceptos horizontales
concepts_html = '<div class="concepts-container">'
for concept, freq in result['key_concepts2']:
concepts_html += f"""
<div class="concept-item">
<span class="concept-name">{concept}</span>
<span class="concept-freq">({freq:.2f})</span>
</div>
"""
concepts_html += '</div>'
st.markdown(concepts_html, unsafe_allow_html=True)
if 'graph2' in result:
with st.container():
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
st.pyplot(result['graph2'])
st.markdown('</div>', unsafe_allow_html=True)
else:
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
else:
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
# Nota informativa sobre la comparaci贸n
st.info(discourse_t.get('comparison_note',
'La funcionalidad de comparaci贸n detallada estar谩 disponible en una pr贸xima actualizaci贸n.'))
##########################################################################################
def display_discourse_results(result, lang_code, discourse_t):
"""
Muestra los resultados del an谩lisis del discurso
"""
if not result.get('success'):
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
return
col1, col2 = st.columns(2)
# Documento 1
with col1:
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
if 'key_concepts1' in result:
df1 = pd.DataFrame(result['key_concepts1'], columns=['Concepto', 'Frecuencia'])
df1['Frecuencia'] = df1['Frecuencia'].round(2)
st.table(df1)
if 'graph1' in result:
st.pyplot(result['graph1'])
else:
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
else:
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
# Documento 2
with col2:
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
if 'key_concepts2' in result:
df2 = pd.DataFrame(result['key_concepts2'], columns=['Concepto', 'Frecuencia'])
df2['Frecuencia'] = df2['Frecuencia'].round(2)
st.table(df2)
if 'graph2' in result:
st.pyplot(result['graph2'])
else:
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
else:
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
# Nota informativa sobre la comparaci贸n
st.info(discourse_t.get('comparison_note',
'La funcionalidad de comparaci贸n detallada estar谩 disponible en una pr贸xima actualizaci贸n.'))