Update modules/discourse/discourse_interface.py
Browse files- modules/discourse/discourse_interface.py +113 -111
modules/discourse/discourse_interface.py
CHANGED
@@ -10,121 +10,123 @@ from ..database.chat_mongo_db import store_chat_history
|
|
10 |
from ..database.discourse_mongo_db import store_student_discourse_result
|
11 |
|
12 |
logger = logging.getLogger(__name__)
|
|
|
13 |
|
14 |
-
def
|
15 |
"""
|
16 |
-
|
17 |
-
Args:
|
18 |
-
lang_code: C贸digo del idioma actual
|
19 |
-
nlp_models: Modelos de spaCy cargados
|
20 |
-
discourse_t: Diccionario de traducciones
|
21 |
"""
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
)
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
|
|
|
128 |
def display_discourse_results(result, lang_code, discourse_t):
|
129 |
"""
|
130 |
Muestra los resultados del an谩lisis del discurso
|
|
|
10 |
from ..database.discourse_mongo_db import store_student_discourse_result
|
11 |
|
12 |
logger = logging.getLogger(__name__)
|
13 |
+
#############################################################################################
|
14 |
|
15 |
+
def display_discourse_results(result, lang_code, discourse_t):
|
16 |
"""
|
17 |
+
Muestra los resultados del an谩lisis del discurso con conceptos en formato horizontal
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
+
if not result.get('success'):
|
20 |
+
st.warning(discourse_t.get('no_results', 'No hay resultados disponibles'))
|
21 |
+
return
|
22 |
+
|
23 |
+
# Estilo CSS para los conceptos horizontales
|
24 |
+
st.markdown("""
|
25 |
+
<style>
|
26 |
+
.concepts-container {
|
27 |
+
display: flex;
|
28 |
+
flex-wrap: nowrap;
|
29 |
+
gap: 8px;
|
30 |
+
padding: 12px;
|
31 |
+
background-color: #f8f9fa;
|
32 |
+
border-radius: 8px;
|
33 |
+
overflow-x: auto;
|
34 |
+
margin-bottom: 15px;
|
35 |
+
}
|
36 |
+
.concept-item {
|
37 |
+
background-color: white;
|
38 |
+
border-radius: 4px;
|
39 |
+
padding: 6px 10px;
|
40 |
+
display: inline-flex;
|
41 |
+
align-items: center;
|
42 |
+
gap: 4px;
|
43 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
44 |
+
flex-shrink: 0;
|
45 |
+
}
|
46 |
+
.concept-name {
|
47 |
+
font-weight: 500;
|
48 |
+
color: #1f2937;
|
49 |
+
font-size: 0.85em;
|
50 |
+
}
|
51 |
+
.concept-freq {
|
52 |
+
color: #6b7280;
|
53 |
+
font-size: 0.75em;
|
54 |
+
}
|
55 |
+
.graph-container {
|
56 |
+
background-color: white;
|
57 |
+
border-radius: 8px;
|
58 |
+
padding: 15px;
|
59 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
60 |
+
margin-top: 10px;
|
61 |
+
}
|
62 |
+
</style>
|
63 |
+
""", unsafe_allow_html=True)
|
64 |
+
|
65 |
+
col1, col2 = st.columns(2)
|
66 |
+
|
67 |
+
# Documento 1
|
68 |
+
with col1:
|
69 |
+
with st.expander(discourse_t.get('doc1_title', 'Documento 1'), expanded=True):
|
70 |
+
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
71 |
+
if 'key_concepts1' in result:
|
72 |
+
# Crear HTML para conceptos horizontales
|
73 |
+
concepts_html = '<div class="concepts-container">'
|
74 |
+
for concept, freq in result['key_concepts1']:
|
75 |
+
concepts_html += f"""
|
76 |
+
<div class="concept-item">
|
77 |
+
<span class="concept-name">{concept}</span>
|
78 |
+
<span class="concept-freq">({freq:.2f})</span>
|
79 |
+
</div>
|
80 |
+
"""
|
81 |
+
concepts_html += '</div>'
|
82 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
83 |
+
|
84 |
+
if 'graph1' in result:
|
85 |
+
with st.container():
|
86 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
87 |
+
st.pyplot(result['graph1'])
|
88 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
89 |
+
else:
|
90 |
+
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
|
91 |
+
else:
|
92 |
+
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
|
93 |
+
|
94 |
+
# Documento 2
|
95 |
+
with col2:
|
96 |
+
with st.expander(discourse_t.get('doc2_title', 'Documento 2'), expanded=True):
|
97 |
+
st.subheader(discourse_t.get('key_concepts', 'Conceptos Clave'))
|
98 |
+
if 'key_concepts2' in result:
|
99 |
+
# Crear HTML para conceptos horizontales
|
100 |
+
concepts_html = '<div class="concepts-container">'
|
101 |
+
for concept, freq in result['key_concepts2']:
|
102 |
+
concepts_html += f"""
|
103 |
+
<div class="concept-item">
|
104 |
+
<span class="concept-name">{concept}</span>
|
105 |
+
<span class="concept-freq">({freq:.2f})</span>
|
106 |
+
</div>
|
107 |
+
"""
|
108 |
+
concepts_html += '</div>'
|
109 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
110 |
+
|
111 |
+
if 'graph2' in result:
|
112 |
+
with st.container():
|
113 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
114 |
+
st.pyplot(result['graph2'])
|
115 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
116 |
+
else:
|
117 |
+
st.warning(discourse_t.get('graph_not_available', 'Gr谩fico no disponible'))
|
118 |
+
else:
|
119 |
+
st.warning(discourse_t.get('concepts_not_available', 'Conceptos no disponibles'))
|
120 |
+
|
121 |
+
# Nota informativa sobre la comparaci贸n
|
122 |
+
st.info(discourse_t.get('comparison_note',
|
123 |
+
'La funcionalidad de comparaci贸n detallada estar谩 disponible en una pr贸xima actualizaci贸n.'))
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
|
129 |
+
##########################################################################################
|
130 |
def display_discourse_results(result, lang_code, discourse_t):
|
131 |
"""
|
132 |
Muestra los resultados del an谩lisis del discurso
|