Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_interface.py
Browse files
modules/semantic/semantic_interface.py
CHANGED
|
@@ -10,6 +10,7 @@ import base64
|
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import pandas as pd
|
| 12 |
import re
|
|
|
|
| 13 |
import logging
|
| 14 |
|
| 15 |
# Configuración del logger
|
|
@@ -25,12 +26,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
|
|
@@ -42,10 +44,7 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 42 |
'pending_analysis': False # Nuevo flag para controlar el análisis pendiente
|
| 43 |
}
|
| 44 |
|
| 45 |
-
# 2. Área de carga de archivo con mensaje informativo
|
| 46 |
-
st.info(semantic_t.get('initial_instruction',
|
| 47 |
-
'Para comenzar un nuevo análisis semántico, cargue un archivo de texto (.txt)'))
|
| 48 |
-
|
| 49 |
uploaded_file = st.file_uploader(
|
| 50 |
semantic_t.get('semantic_file_uploader', 'Upload a text file for semantic analysis'),
|
| 51 |
type=['txt'],
|
|
@@ -53,11 +52,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,
|
|
@@ -122,17 +124,42 @@ def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
|
| 122 |
# 6. Mostrar resultados previos o mensaje inicial
|
| 123 |
elif 'semantic_result' in st.session_state and st.session_state.semantic_result is not None:
|
| 124 |
# Mostrar mensaje sobre el análisis actual
|
| 125 |
-
st.info(
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
)
|
| 130 |
|
| 131 |
display_semantic_results(
|
| 132 |
st.session_state.semantic_result,
|
| 133 |
lang_code,
|
| 134 |
semantic_t
|
| 135 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
else:
|
| 137 |
st.info(semantic_t.get('upload_prompt', 'Cargue un archivo para comenzar el análisis'))
|
| 138 |
|
|
@@ -257,5 +284,4 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
| 257 |
logger.error(f"Error displaying graph: {str(e)}")
|
| 258 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
| 259 |
else:
|
| 260 |
-
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
| 261 |
-
|
|
|
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import pandas as pd
|
| 12 |
import re
|
| 13 |
+
|
| 14 |
import logging
|
| 15 |
|
| 16 |
# Configuración del logger
|
|
|
|
| 26 |
from ..database.semantic_mongo_db import store_student_semantic_result
|
| 27 |
from ..database.chat_mongo_db import store_chat_history, get_chat_history
|
| 28 |
|
| 29 |
+
from ..semantic.semantic_agent_interaction import display_semantic_chat
|
| 30 |
+
from ..chatbot.sidebar_chat import display_sidebar_chat
|
| 31 |
|
| 32 |
+
# from ..database.semantic_export import export_user_interactions
|
| 33 |
|
| 34 |
###############################
|
| 35 |
|
|
|
|
| 36 |
def display_semantic_interface(lang_code, nlp_models, semantic_t):
|
| 37 |
try:
|
| 38 |
# 1. Inicializar el estado de la sesión
|
|
|
|
| 44 |
'pending_analysis': False # Nuevo flag para controlar el análisis pendiente
|
| 45 |
}
|
| 46 |
|
| 47 |
+
# 2. Área de carga de archivo con mensaje informativo
|
|
|
|
|
|
|
|
|
|
| 48 |
uploaded_file = st.file_uploader(
|
| 49 |
semantic_t.get('semantic_file_uploader', 'Upload a text file for semantic analysis'),
|
| 50 |
type=['txt'],
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
# 2.1 Verificar si hay un archivo cargado y un análisis pendiente
|
| 55 |
+
|
| 56 |
if uploaded_file is not None and st.session_state.semantic_state.get('pending_analysis', False):
|
| 57 |
+
|
| 58 |
try:
|
| 59 |
with st.spinner(semantic_t.get('processing', 'Processing...')):
|
| 60 |
# Realizar análisis
|
| 61 |
text_content = uploaded_file.getvalue().decode('utf-8')
|
| 62 |
+
st.session_state.semantic_state['text_content'] = text_content # <-- Guardar el texto
|
| 63 |
|
| 64 |
analysis_result = process_semantic_input(
|
| 65 |
text_content,
|
|
|
|
| 124 |
# 6. Mostrar resultados previos o mensaje inicial
|
| 125 |
elif 'semantic_result' in st.session_state and st.session_state.semantic_result is not None:
|
| 126 |
# Mostrar mensaje sobre el análisis actual
|
| 127 |
+
#st.info(
|
| 128 |
+
# semantic_t.get('current_analysis_message',
|
| 129 |
+
# 'Mostrando análisis del archivo: {}. Para realizar un nuevo análisis, cargue otro archivo.'
|
| 130 |
+
# ).format(st.session_state.semantic_state["current_file"])
|
| 131 |
+
#)
|
| 132 |
|
| 133 |
display_semantic_results(
|
| 134 |
st.session_state.semantic_result,
|
| 135 |
lang_code,
|
| 136 |
semantic_t
|
| 137 |
)
|
| 138 |
+
|
| 139 |
+
# --- BOTÓN PARA ACTIVAR EL AGENTE VIRTUAL (NUEVA POSICIÓN CORRECTA) ---
|
| 140 |
+
if st.button(
|
| 141 |
+
"💬 " + semantic_t.get('semantic_virtual_agent_button', 'Analizar con Agente Virtual'),
|
| 142 |
+
key="activate_semantic_agent",
|
| 143 |
+
use_container_width=True,
|
| 144 |
+
type="primary"
|
| 145 |
+
):
|
| 146 |
+
|
| 147 |
+
# Obtener el texto analizado
|
| 148 |
+
text_content = st.session_state.semantic_state.get('text_content', "")
|
| 149 |
+
|
| 150 |
+
st.session_state.semantic_agent_active = True
|
| 151 |
+
st.session_state.semantic_agent_data = {
|
| 152 |
+
'text': text_content,
|
| 153 |
+
'metrics': st.session_state.semantic_result['analysis'],
|
| 154 |
+
'graph_data': st.session_state.semantic_result['analysis'].get('concept_graph')
|
| 155 |
+
}
|
| 156 |
+
st.success(semantic_t.get('semantic_agent_ready_message', 'Análisis enviado al agente virtual. Abre el chat para conversar.'))
|
| 157 |
+
st.rerun()
|
| 158 |
+
|
| 159 |
+
# Mostrar notificación si el agente está activo
|
| 160 |
+
if st.session_state.get('semantic_agent_active', False):
|
| 161 |
+
st.success(semantic_t.get('semantic_agent_ready_message', 'El agente virtual está listo. Abre el chat en la barra lateral.'))
|
| 162 |
+
|
| 163 |
else:
|
| 164 |
st.info(semantic_t.get('upload_prompt', 'Cargue un archivo para comenzar el análisis'))
|
| 165 |
|
|
|
|
| 284 |
logger.error(f"Error displaying graph: {str(e)}")
|
| 285 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
| 286 |
else:
|
| 287 |
+
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
|
|