Spaces:
Sleeping
Sleeping
Update modules/ui/ui.py
Browse files- modules/ui/ui.py +64 -14
modules/ui/ui.py
CHANGED
|
@@ -403,6 +403,17 @@ def user_page(lang_code, t):
|
|
| 403 |
# Mostrar chatbot en sidebar
|
| 404 |
display_sidebar_chat(lang_code, chatbot_t)
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
# Sistema de tabs
|
| 407 |
tab_names = [
|
| 408 |
t.get('morpho_tab', 'Análisis Morfosintáctico'),
|
|
@@ -417,59 +428,98 @@ def user_page(lang_code, t):
|
|
| 417 |
|
| 418 |
# Manejar el contenido de cada tab
|
| 419 |
for index, tab in enumerate(tabs):
|
| 420 |
-
if tab.selected:
|
| 421 |
-
st.session_state.selected_tab = index
|
| 422 |
-
|
| 423 |
with tab:
|
| 424 |
try:
|
| 425 |
-
# Actualizar el tab seleccionado solo si
|
| 426 |
if tab.selected and st.session_state.selected_tab != index:
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
st.session_state.selected_tab = index
|
| 429 |
-
|
| 430 |
-
if index == 0:
|
|
|
|
| 431 |
display_morphosyntax_interface(
|
| 432 |
st.session_state.lang_code,
|
| 433 |
st.session_state.nlp_models,
|
| 434 |
t.get('TRANSLATIONS', {})
|
| 435 |
)
|
| 436 |
|
| 437 |
-
elif index == 1: #
|
|
|
|
| 438 |
display_semantic_live_interface(
|
| 439 |
st.session_state.lang_code,
|
| 440 |
st.session_state.nlp_models,
|
| 441 |
t.get('TRANSLATIONS', {})
|
| 442 |
)
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
display_semantic_interface(
|
| 447 |
st.session_state.lang_code,
|
| 448 |
st.session_state.nlp_models,
|
| 449 |
t.get('TRANSLATIONS', {})
|
| 450 |
)
|
| 451 |
|
| 452 |
-
elif index == 3:
|
|
|
|
| 453 |
display_discourse_interface(
|
| 454 |
st.session_state.lang_code,
|
| 455 |
st.session_state.nlp_models,
|
| 456 |
t.get('TRANSLATIONS', {})
|
| 457 |
)
|
| 458 |
-
|
|
|
|
|
|
|
| 459 |
display_student_activities(
|
| 460 |
username=st.session_state.username,
|
| 461 |
lang_code=st.session_state.lang_code,
|
| 462 |
t=t.get('ACTIVITIES_TRANSLATIONS', {})
|
| 463 |
)
|
| 464 |
-
|
|
|
|
|
|
|
| 465 |
display_feedback_form(
|
| 466 |
st.session_state.lang_code,
|
| 467 |
t
|
| 468 |
)
|
|
|
|
| 469 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
logger.error(f"Error en tab {index}: {str(e)}")
|
| 471 |
st.error(t.get('tab_error', 'Error al cargar esta sección'))
|
| 472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
# Panel de depuración (solo visible en desarrollo)
|
| 474 |
if st.session_state.get('debug_mode', False):
|
| 475 |
with st.expander("Debug Info"):
|
|
|
|
| 403 |
# Mostrar chatbot en sidebar
|
| 404 |
display_sidebar_chat(lang_code, chatbot_t)
|
| 405 |
|
| 406 |
+
# Inicializar estados para todos los tabs
|
| 407 |
+
if 'tab_states' not in st.session_state:
|
| 408 |
+
st.session_state.tab_states = {
|
| 409 |
+
'morpho_active': False,
|
| 410 |
+
'semantic_live_active': False,
|
| 411 |
+
'semantic_active': False,
|
| 412 |
+
'discourse_active': False,
|
| 413 |
+
'activities_active': False,
|
| 414 |
+
'feedback_active': False
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
# Sistema de tabs
|
| 418 |
tab_names = [
|
| 419 |
t.get('morpho_tab', 'Análisis Morfosintáctico'),
|
|
|
|
| 428 |
|
| 429 |
# Manejar el contenido de cada tab
|
| 430 |
for index, tab in enumerate(tabs):
|
|
|
|
|
|
|
|
|
|
| 431 |
with tab:
|
| 432 |
try:
|
| 433 |
+
# Actualizar el tab seleccionado solo si no hay un análisis activo
|
| 434 |
if tab.selected and st.session_state.selected_tab != index:
|
| 435 |
+
can_switch = True
|
| 436 |
+
for state_key in st.session_state.tab_states.keys():
|
| 437 |
+
if st.session_state.tab_states[state_key] and index != get_tab_index(state_key):
|
| 438 |
+
can_switch = False
|
| 439 |
+
break
|
| 440 |
+
if can_switch:
|
| 441 |
st.session_state.selected_tab = index
|
| 442 |
+
|
| 443 |
+
if index == 0: # Morfosintáctico
|
| 444 |
+
st.session_state.tab_states['morpho_active'] = True
|
| 445 |
display_morphosyntax_interface(
|
| 446 |
st.session_state.lang_code,
|
| 447 |
st.session_state.nlp_models,
|
| 448 |
t.get('TRANSLATIONS', {})
|
| 449 |
)
|
| 450 |
|
| 451 |
+
elif index == 1: # Semántico Vivo
|
| 452 |
+
st.session_state.tab_states['semantic_live_active'] = True
|
| 453 |
display_semantic_live_interface(
|
| 454 |
st.session_state.lang_code,
|
| 455 |
st.session_state.nlp_models,
|
| 456 |
t.get('TRANSLATIONS', {})
|
| 457 |
)
|
| 458 |
+
|
| 459 |
+
elif index == 2: # Semántico
|
| 460 |
+
st.session_state.tab_states['semantic_active'] = True
|
| 461 |
display_semantic_interface(
|
| 462 |
st.session_state.lang_code,
|
| 463 |
st.session_state.nlp_models,
|
| 464 |
t.get('TRANSLATIONS', {})
|
| 465 |
)
|
| 466 |
|
| 467 |
+
elif index == 3: # Discurso
|
| 468 |
+
st.session_state.tab_states['discourse_active'] = True
|
| 469 |
display_discourse_interface(
|
| 470 |
st.session_state.lang_code,
|
| 471 |
st.session_state.nlp_models,
|
| 472 |
t.get('TRANSLATIONS', {})
|
| 473 |
)
|
| 474 |
+
|
| 475 |
+
elif index == 4: # Actividades
|
| 476 |
+
st.session_state.tab_states['activities_active'] = True
|
| 477 |
display_student_activities(
|
| 478 |
username=st.session_state.username,
|
| 479 |
lang_code=st.session_state.lang_code,
|
| 480 |
t=t.get('ACTIVITIES_TRANSLATIONS', {})
|
| 481 |
)
|
| 482 |
+
|
| 483 |
+
elif index == 5: # Feedback
|
| 484 |
+
st.session_state.tab_states['feedback_active'] = True
|
| 485 |
display_feedback_form(
|
| 486 |
st.session_state.lang_code,
|
| 487 |
t
|
| 488 |
)
|
| 489 |
+
|
| 490 |
except Exception as e:
|
| 491 |
+
# Desactivar el estado en caso de error
|
| 492 |
+
state_key = get_state_key_for_index(index)
|
| 493 |
+
if state_key:
|
| 494 |
+
st.session_state.tab_states[state_key] = False
|
| 495 |
logger.error(f"Error en tab {index}: {str(e)}")
|
| 496 |
st.error(t.get('tab_error', 'Error al cargar esta sección'))
|
| 497 |
|
| 498 |
+
# Funciones auxiliares para manejar los estados de los tabs
|
| 499 |
+
def get_tab_index(state_key):
|
| 500 |
+
"""Obtiene el índice del tab basado en la clave de estado"""
|
| 501 |
+
index_map = {
|
| 502 |
+
'morpho_active': 0,
|
| 503 |
+
'semantic_live_active': 1,
|
| 504 |
+
'semantic_active': 2,
|
| 505 |
+
'discourse_active': 3,
|
| 506 |
+
'activities_active': 4,
|
| 507 |
+
'feedback_active': 5
|
| 508 |
+
}
|
| 509 |
+
return index_map.get(state_key, -1)
|
| 510 |
+
|
| 511 |
+
def get_state_key_for_index(index):
|
| 512 |
+
"""Obtiene la clave de estado basada en el índice del tab"""
|
| 513 |
+
state_map = {
|
| 514 |
+
0: 'morpho_active',
|
| 515 |
+
1: 'semantic_live_active',
|
| 516 |
+
2: 'semantic_active',
|
| 517 |
+
3: 'discourse_active',
|
| 518 |
+
4: 'activities_active',
|
| 519 |
+
5: 'feedback_active'
|
| 520 |
+
}
|
| 521 |
+
return state_map.get(index)
|
| 522 |
+
|
| 523 |
# Panel de depuración (solo visible en desarrollo)
|
| 524 |
if st.session_state.get('debug_mode', False):
|
| 525 |
with st.expander("Debug Info"):
|