AIdeaText commited on
Commit
9bcd9c9
1 Parent(s): d8bf136

Update modules/discourse/discourse_live_interface.py

Browse files
modules/discourse/discourse_live_interface.py CHANGED
@@ -5,6 +5,8 @@ from streamlit_float import *
5
  from streamlit_antd_components import *
6
  import pandas as pd
7
  import logging
 
 
8
 
9
  # Configuración del logger
10
  logger = logging.getLogger(__name__)
@@ -15,6 +17,17 @@ from ..utils.widget_utils import generate_unique_key
15
  from ..database.discourse_mongo_db import store_student_discourse_result
16
  from ..database.chat_mongo_db import store_chat_history, get_chat_history
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  def display_discourse_live_interface(lang_code, nlp_models, discourse_t):
19
  """
20
  Interfaz para el análisis del discurso en vivo
@@ -92,6 +105,12 @@ def display_discourse_live_interface(lang_code, nlp_models, discourse_t):
92
  )
93
 
94
  if result['success']:
 
 
 
 
 
 
95
  st.session_state.discourse_live_state['last_result'] = result
96
  st.session_state.discourse_live_state['analysis_count'] += 1
97
  st.session_state.discourse_live_state['text_changed'] = False
@@ -110,6 +129,7 @@ def display_discourse_live_interface(lang_code, nlp_models, discourse_t):
110
  logger.error(f"Error en análisis: {str(e)}")
111
  st.error(discourse_t.get('error_processing', 'Error al procesar el texto'))
112
 
 
113
  # Columna derecha: Visualización de resultados
114
  with result_col:
115
  st.subheader(discourse_t.get('live_results', 'Resultados en vivo'))
 
5
  from streamlit_antd_components import *
6
  import pandas as pd
7
  import logging
8
+ import io
9
+ import matplotlib.pyplot as plt
10
 
11
  # Configuración del logger
12
  logger = logging.getLogger(__name__)
 
17
  from ..database.discourse_mongo_db import store_student_discourse_result
18
  from ..database.chat_mongo_db import store_chat_history, get_chat_history
19
 
20
+ def fig_to_bytes(fig):
21
+ """Convierte una figura de matplotlib a bytes."""
22
+ try:
23
+ buf = io.BytesIO()
24
+ fig.savefig(buf, format='png', dpi=300, bbox_inches='tight')
25
+ buf.seek(0)
26
+ return buf.getvalue()
27
+ except Exception as e:
28
+ logger.error(f"Error en fig_to_bytes: {str(e)}")
29
+ return None
30
+
31
  def display_discourse_live_interface(lang_code, nlp_models, discourse_t):
32
  """
33
  Interfaz para el análisis del discurso en vivo
 
105
  )
106
 
107
  if result['success']:
108
+ # Convertir gráficos a bytes antes de guardar
109
+ if 'graph1' in result:
110
+ result['graph1_bytes'] = fig_to_bytes(result['graph1'])
111
+ if 'graph2' in result:
112
+ result['graph2_bytes'] = fig_to_bytes(result['graph2'])
113
+
114
  st.session_state.discourse_live_state['last_result'] = result
115
  st.session_state.discourse_live_state['analysis_count'] += 1
116
  st.session_state.discourse_live_state['text_changed'] = False
 
129
  logger.error(f"Error en análisis: {str(e)}")
130
  st.error(discourse_t.get('error_processing', 'Error al procesar el texto'))
131
 
132
+
133
  # Columna derecha: Visualización de resultados
134
  with result_col:
135
  st.subheader(discourse_t.get('live_results', 'Resultados en vivo'))