Spaces:
Running
Running
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
@@ -25,12 +25,13 @@ from ..utils.widget_utils import generate_unique_key
|
|
25 |
from ..database.semantic_mongo_db import store_student_semantic_result
|
26 |
from ..database.chat_mongo_db import store_chat_history, get_chat_history
|
27 |
|
28 |
-
|
|
|
29 |
|
|
|
30 |
|
31 |
###############################
|
32 |
|
33 |
-
# En semantic_interface.py
|
34 |
def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
35 |
try:
|
36 |
# 1. Inicializar el estado de la sesi贸n
|
@@ -53,11 +54,14 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
53 |
)
|
54 |
|
55 |
# 2.1 Verificar si hay un archivo cargado y un an谩lisis pendiente
|
|
|
56 |
if uploaded_file is not None and st.session_state.semantic_state.get('pending_analysis', False):
|
|
|
57 |
try:
|
58 |
with st.spinner(semantic_t.get('processing', 'Processing...')):
|
59 |
# Realizar an谩lisis
|
60 |
text_content = uploaded_file.getvalue().decode('utf-8')
|
|
|
61 |
|
62 |
analysis_result = process_semantic_input(
|
63 |
text_content,
|
@@ -136,6 +140,32 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
136 |
else:
|
137 |
st.info(semantic_t.get('upload_prompt', 'Cargue un archivo para comenzar el an谩lisis'))
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
except Exception as e:
|
140 |
logger.error(f"Error general en interfaz sem谩ntica: {str(e)}")
|
141 |
st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|
|
|
25 |
from ..database.semantic_mongo_db import store_student_semantic_result
|
26 |
from ..database.chat_mongo_db import store_chat_history, get_chat_history
|
27 |
|
28 |
+
from ..semantic.semantic_agent_interaction import display_semantic_chat
|
29 |
+
from ..chatbot.sidebar_chat import display_sidebar_chat
|
30 |
|
31 |
+
# from ..database.semantic_export import export_user_interactions
|
32 |
|
33 |
###############################
|
34 |
|
|
|
35 |
def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
36 |
try:
|
37 |
# 1. Inicializar el estado de la sesi贸n
|
|
|
54 |
)
|
55 |
|
56 |
# 2.1 Verificar si hay un archivo cargado y un an谩lisis pendiente
|
57 |
+
|
58 |
if uploaded_file is not None and st.session_state.semantic_state.get('pending_analysis', False):
|
59 |
+
|
60 |
try:
|
61 |
with st.spinner(semantic_t.get('processing', 'Processing...')):
|
62 |
# Realizar an谩lisis
|
63 |
text_content = uploaded_file.getvalue().decode('utf-8')
|
64 |
+
st.session_state.semantic_state['text_content'] = text_content # <-- Guardar el texto
|
65 |
|
66 |
analysis_result = process_semantic_input(
|
67 |
text_content,
|
|
|
140 |
else:
|
141 |
st.info(semantic_t.get('upload_prompt', 'Cargue un archivo para comenzar el an谩lisis'))
|
142 |
|
143 |
+
# --- NUEVA SECCI脫N: Bot贸n para activar el agente virtual ---
|
144 |
+
if st.button(
|
145 |
+
"馃挰 " + semantic_t.get('virtual_agent_button', 'Analizar con Agente Virtual'),
|
146 |
+
key="activate_semantic_agent",
|
147 |
+
use_container_width=True
|
148 |
+
):
|
149 |
+
# Obtener el texto analizado (debemos asegurarnos de tenerlo disponible)
|
150 |
+
text_content = ""
|
151 |
+
if uploaded_file:
|
152 |
+
text_content = uploaded_file.getvalue().decode('utf-8')
|
153 |
+
elif 'semantic_state' in st.session_state and st.session_state.semantic_state.get('current_file'):
|
154 |
+
# Recuperar de sesi贸n si ya se analiz贸
|
155 |
+
text_content = st.session_state.semantic_state.get('text_content', "")
|
156 |
+
|
157 |
+
st.session_state.semantic_agent_active = True
|
158 |
+
st.session_state.semantic_agent_data = {
|
159 |
+
'text': text_content,
|
160 |
+
'metrics': st.session_state.semantic_result['analysis'],
|
161 |
+
'graph_data': st.session_state.semantic_result['analysis'].get('concept_graph')
|
162 |
+
}
|
163 |
+
st.rerun()
|
164 |
+
|
165 |
+
# Mostrar notificaci贸n si el agente est谩 activo
|
166 |
+
if st.session_state.get('semantic_agent_active', False):
|
167 |
+
st.success(semantic_t.get('agent_ready_message', 'El agente virtual ha recibido tu an谩lisis. Abre el asistente en la barra lateral para conversar.'))
|
168 |
+
|
169 |
except Exception as e:
|
170 |
logger.error(f"Error general en interfaz sem谩ntica: {str(e)}")
|
171 |
st.error(semantic_t.get('general_error', "Se produjo un error. Por favor, intente de nuevo."))
|