AIdeaText commited on
Commit
f6cb5d5
verified
1 Parent(s): b9f1fb6

Update modules/semantic/semantic_live_interface.py

Browse files
modules/semantic/semantic_live_interface.py CHANGED
@@ -21,76 +21,16 @@ from ..database.chat_mongo_db import store_chat_history, get_chat_history
21
  def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
22
  """
23
  Interfaz para el an谩lisis sem谩ntico en vivo
24
- Args:
25
- lang_code: C贸digo del idioma actual
26
- nlp_models: Modelos de spaCy cargados
27
- semantic_t: Diccionario de traducciones sem谩nticas
28
  """
29
  try:
30
- # 1. Inicializar el estado de la sesi贸n para el an谩lisis en vivo
31
- if 'semantic_live_state' not in st.session_state:
32
- st.session_state.semantic_live_state = {
33
- 'analysis_count': 0,
34
- 'last_analysis': None,
35
- 'current_text': '',
36
- 'last_result': None
37
- }
38
-
39
- # 2. Crear dos columnas
40
- col1, col2 = st.columns(2)
41
-
42
- # Columna izquierda: Entrada de texto
43
- with col1:
44
- st.subheader(semantic_t.get('enter_text', 'Ingrese su texto'))
45
-
46
- # 脕rea de texto para input
47
- text_input = st.text_area(
48
- semantic_t.get('text_input_label', 'Escriba o pegue su texto aqu铆'),
49
- height=400,
50
- key="semantic_live_text",
51
- value=st.session_state.semantic_live_state.get('current_text', '')
52
- )
53
-
54
- # Actualizar el texto actual en el estado
55
- st.session_state.semantic_live_state['current_text'] = text_input
56
-
57
- # Bot贸n de an谩lisis
58
- analyze_button = st.button(
59
- semantic_t.get('analyze_button', 'Analizar'),
60
- key="semantic_live_analyze",
61
- type="primary",
62
- icon="馃攳",
63
- disabled=not text_input,
64
- use_container_width=True
65
- )
66
 
67
  # Columna derecha: Visualizaci贸n de resultados
68
  with col2:
69
  st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
70
 
71
  try:
72
- # Procesar an谩lisis cuando se presiona el bot贸n
73
- if analyze_button and text_input:
74
- with st.spinner(semantic_t.get('processing', 'Procesando...')):
75
- # Realizar an谩lisis
76
- analysis_result = process_semantic_input(
77
- text_input,
78
- lang_code,
79
- nlp_models,
80
- semantic_t
81
- )
82
-
83
- if analysis_result['success']:
84
- # Guardar resultado en el estado
85
- st.session_state.semantic_live_state['last_result'] = analysis_result
86
- st.session_state.semantic_live_state['analysis_count'] += 1
87
-
88
- # Guardar en base de datos
89
- store_student_semantic_result(
90
- st.session_state.username,
91
- text_input,
92
- analysis_result['analysis']
93
- )
94
 
95
  # Mostrar resultados (ya sea nuevos o previos)
96
  if 'last_result' in st.session_state.semantic_live_state and \
@@ -100,52 +40,52 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
100
 
101
  # Mostrar conceptos clave en formato horizontal
102
  if 'key_concepts' in analysis and analysis['key_concepts']:
103
- st.markdown(
104
- """
105
  <style>
106
  .concept-table {
107
  display: flex;
108
  flex-wrap: wrap;
109
  gap: 10px;
110
  margin-bottom: 20px;
 
 
 
111
  }
112
  .concept-item {
113
- background-color: #f0f2f6;
114
  border-radius: 5px;
115
  padding: 8px 12px;
116
  display: flex;
117
  align-items: center;
118
  gap: 8px;
 
119
  }
120
  .concept-name {
121
- font-weight: bold;
 
122
  }
123
  .concept-freq {
124
- color: #666;
125
  font-size: 0.9em;
126
  }
127
  </style>
128
- """,
129
- unsafe_allow_html=True
 
 
 
 
 
 
130
  )
131
-
132
- # Crear la visualizaci贸n horizontal de conceptos
133
- concepts_html = '<div class="concept-table">'
134
- for concept, freq in analysis['key_concepts']:
135
- concepts_html += f'''
136
- <div class="concept-item">
137
- <span class="concept-name">{concept}</span>
138
- <span class="concept-freq">({freq:.2f})</span>
139
- </div>
140
- '''
141
- concepts_html += '</div>'
142
- st.markdown(concepts_html, unsafe_allow_html=True)
143
 
144
  # Mostrar gr谩fico de conceptos
145
  if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
146
  # Container para el grafo con estilos mejorados
147
- st.markdown(
148
- """
149
  <style>
150
  .graph-container {
151
  background-color: white;
@@ -155,21 +95,20 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
155
  margin: 10px 0;
156
  }
157
  </style>
158
- """,
159
- unsafe_allow_html=True
160
- )
161
 
162
  with st.container():
163
  st.markdown('<div class="graph-container">', unsafe_allow_html=True)
164
 
165
- # Mostrar grafo
166
- st.image(analysis['concept_graph'], use_column_width=True)
167
-
168
- # Leyenda del grafo
169
- st.caption(semantic_t.get(
170
- 'graph_description',
171
- 'Visualizaci贸n de relaciones entre conceptos clave identificados en el texto.'
172
- ))
 
173
 
174
  st.markdown('</div>', unsafe_allow_html=True)
175
 
 
21
  def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
22
  """
23
  Interfaz para el an谩lisis sem谩ntico en vivo
 
 
 
 
24
  """
25
  try:
26
+ # [C贸digo anterior sin cambios hasta la visualizaci贸n de conceptos]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  # Columna derecha: Visualizaci贸n de resultados
29
  with col2:
30
  st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
31
 
32
  try:
33
+ # [C贸digo del procesamiento sin cambios]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # Mostrar resultados (ya sea nuevos o previos)
36
  if 'last_result' in st.session_state.semantic_live_state and \
 
40
 
41
  # Mostrar conceptos clave en formato horizontal
42
  if 'key_concepts' in analysis and analysis['key_concepts']:
43
+ st.markdown("""
 
44
  <style>
45
  .concept-table {
46
  display: flex;
47
  flex-wrap: wrap;
48
  gap: 10px;
49
  margin-bottom: 20px;
50
+ padding: 10px;
51
+ background-color: #f8f9fa;
52
+ border-radius: 8px;
53
  }
54
  .concept-item {
55
+ background-color: white;
56
  border-radius: 5px;
57
  padding: 8px 12px;
58
  display: flex;
59
  align-items: center;
60
  gap: 8px;
61
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
62
  }
63
  .concept-name {
64
+ font-weight: 500;
65
+ color: #1f2937;
66
  }
67
  .concept-freq {
68
+ color: #6b7280;
69
  font-size: 0.9em;
70
  }
71
  </style>
72
+ """, unsafe_allow_html=True)
73
+
74
+ # Crear la visualizaci贸n horizontal de conceptos de manera m谩s compacta
75
+ concepts_html = ['<div class="concept-table">']
76
+ concepts_html.extend(
77
+ f'<div class="concept-item"><span class="concept-name">{concept}</span>'
78
+ f'<span class="concept-freq">({freq:.2f})</span></div>'
79
+ for concept, freq in analysis['key_concepts']
80
  )
81
+ concepts_html.append('</div>')
82
+
83
+ st.markdown(''.join(concepts_html), unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
84
 
85
  # Mostrar gr谩fico de conceptos
86
  if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
87
  # Container para el grafo con estilos mejorados
88
+ st.markdown("""
 
89
  <style>
90
  .graph-container {
91
  background-color: white;
 
95
  margin: 10px 0;
96
  }
97
  </style>
98
+ """, unsafe_allow_html=True)
 
 
99
 
100
  with st.container():
101
  st.markdown('<div class="graph-container">', unsafe_allow_html=True)
102
 
103
+ # Mostrar grafo con el par谩metro actualizado
104
+ st.image(
105
+ analysis['concept_graph'],
106
+ use_container_width=True, # Par谩metro actualizado
107
+ caption=semantic_t.get(
108
+ 'graph_description',
109
+ 'Visualizaci贸n de relaciones entre conceptos clave identificados en el texto.'
110
+ )
111
+ )
112
 
113
  st.markdown('</div>', unsafe_allow_html=True)
114