Spaces:
Sleeping
Sleeping
Update modules/ui/ui.py
Browse files- modules/ui/ui.py +123 -122
modules/ui/ui.py
CHANGED
|
@@ -372,7 +372,7 @@ def display_videos_and_info(lang_code, t):
|
|
| 372 |
|
| 373 |
#Después de iniciar sesión
|
| 374 |
####################################
|
| 375 |
-
|
| 376 |
def user_page(lang_code, t):
|
| 377 |
logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}")
|
| 378 |
|
|
@@ -445,7 +445,7 @@ def user_page(lang_code, t):
|
|
| 445 |
st.markdown("---")
|
| 446 |
|
| 447 |
# Asegurarse de que tenemos las traducciones del chatbot
|
| 448 |
-
chatbot_t = t.get('CHATBOT_TRANSLATIONS', {})
|
| 449 |
|
| 450 |
# Mostrar chatbot en sidebar
|
| 451 |
display_sidebar_chat(lang_code, chatbot_t)
|
|
@@ -465,131 +465,131 @@ def user_page(lang_code, t):
|
|
| 465 |
|
| 466 |
# Sistema de tabs
|
| 467 |
tab_names = [
|
| 468 |
-
t.get('current_situation_tab', "Mi Situación Actual"),
|
| 469 |
-
t.get('morpho_tab', 'Análisis Morfosintáctico'),
|
| 470 |
-
t.get('semantic_live_tab', 'Análisis Semántico Vivo'),
|
| 471 |
-
t.get('semantic_tab', 'Análisis Semántico'),
|
| 472 |
-
t.get('discourse_live_tab', 'Análisis de Discurso Vivo'),
|
| 473 |
-
t.get('discourse_tab', 'Análsis de Discurso'),
|
| 474 |
-
t.get('activities_tab', 'Mis Actividades'),
|
| 475 |
-
t.get('feedback_tab', 'Formulario de Comentarios')
|
| 476 |
]
|
| 477 |
|
| 478 |
tabs = st.tabs(tab_names)
|
| 479 |
|
| 480 |
-
# Manejar el contenido de cada tab
|
| 481 |
-
for index, tab in enumerate(tabs):
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
)
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
3: 'semantic_active',
|
| 587 |
-
4: 'discourse_live_active',
|
| 588 |
-
5: 'discourse_active',
|
| 589 |
-
6: 'activities_active',
|
| 590 |
-
7: 'feedback_active'
|
| 591 |
-
}
|
| 592 |
-
return state_map.get(index)
|
| 593 |
|
| 594 |
# Panel de depuración (solo visible en desarrollo)
|
| 595 |
if st.session_state.get('debug_mode', False):
|
|
@@ -601,6 +601,7 @@ def get_state_key_for_index(index):
|
|
| 601 |
st.write(f"Tab seleccionado: {st.session_state.selected_tab}")
|
| 602 |
st.write(f"Última actualización de datos: {st.session_state.get('last_data_fetch', 'Nunca')}")
|
| 603 |
|
|
|
|
| 604 |
########################################################################
|
| 605 |
def display_feedback_form(lang_code, t):
|
| 606 |
logging.info(f"display_feedback_form called with lang_code: {lang_code}")
|
|
|
|
| 372 |
|
| 373 |
#Después de iniciar sesión
|
| 374 |
####################################
|
| 375 |
+
####################################
|
| 376 |
def user_page(lang_code, t):
|
| 377 |
logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}")
|
| 378 |
|
|
|
|
| 445 |
st.markdown("---")
|
| 446 |
|
| 447 |
# Asegurarse de que tenemos las traducciones del chatbot
|
| 448 |
+
chatbot_t = t.get('CHATBOT_TRANSLATIONS', {})
|
| 449 |
|
| 450 |
# Mostrar chatbot en sidebar
|
| 451 |
display_sidebar_chat(lang_code, chatbot_t)
|
|
|
|
| 465 |
|
| 466 |
# Sistema de tabs
|
| 467 |
tab_names = [
|
| 468 |
+
t.get('TABS', {}).get('current_situation_tab', "Mi Situación Actual"),
|
| 469 |
+
t.get('TABS', {}).get('morpho_tab', 'Análisis Morfosintáctico'),
|
| 470 |
+
t.get('TABS', {}).get('semantic_live_tab', 'Análisis Semántico Vivo'),
|
| 471 |
+
t.get('TABS', {}).get('semantic_tab', 'Análisis Semántico'),
|
| 472 |
+
t.get('TABS', {}).get('discourse_live_tab', 'Análisis de Discurso Vivo'),
|
| 473 |
+
t.get('TABS', {}).get('discourse_tab', 'Análsis de Discurso'),
|
| 474 |
+
t.get('TABS', {}).get('activities_tab', 'Mis Actividades'),
|
| 475 |
+
t.get('TABS', {}).get('feedback_tab', 'Formulario de Comentarios')
|
| 476 |
]
|
| 477 |
|
| 478 |
tabs = st.tabs(tab_names)
|
| 479 |
|
| 480 |
+
# Manejar el contenido de cada tab
|
| 481 |
+
for index, tab in enumerate(tabs):
|
| 482 |
+
with tab:
|
| 483 |
+
try:
|
| 484 |
+
# Actualizar el tab seleccionado solo si no hay un análisis activo
|
| 485 |
+
if tab.selected and st.session_state.selected_tab != index:
|
| 486 |
+
can_switch = True
|
| 487 |
+
for state_key in st.session_state.tab_states.keys():
|
| 488 |
+
if st.session_state.tab_states[state_key] and index != get_tab_index(state_key):
|
| 489 |
+
can_switch = False
|
| 490 |
+
break
|
| 491 |
+
if can_switch:
|
| 492 |
+
st.session_state.selected_tab = index
|
| 493 |
+
|
| 494 |
+
if index == 0: # Situación actual
|
| 495 |
+
st.session_state.tab_states['current_situation_active'] = True
|
| 496 |
+
display_current_situation_interface(
|
| 497 |
+
lang_code=st.session_state.lang_code,
|
| 498 |
+
nlp_models=st.session_state.nlp_models,
|
| 499 |
+
current_situation_t=t.get('CURRENT_SITUATION', {})
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
elif index == 1: # Morfosintáctico
|
| 503 |
+
st.session_state.tab_states['morpho_active'] = True
|
| 504 |
+
display_morphosyntax_interface(
|
| 505 |
+
lang_code=st.session_state.lang_code,
|
| 506 |
+
nlp_models=st.session_state.nlp_models,
|
| 507 |
+
morpho_t=t.get('MORPHOSYNTACTIC', {})
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
elif index == 2: # Semántico Vivo
|
| 511 |
+
st.session_state.tab_states['semantic_live_active'] = True
|
| 512 |
+
display_semantic_live_interface(
|
| 513 |
+
lang_code=st.session_state.lang_code,
|
| 514 |
+
nlp_models=st.session_state.nlp_models,
|
| 515 |
+
semantic_t=t.get('SEMANTIC', {})
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
elif index == 3: # Semántico
|
| 519 |
+
st.session_state.tab_states['semantic_active'] = True
|
| 520 |
+
display_semantic_interface(
|
| 521 |
+
lang_code=st.session_state.lang_code,
|
| 522 |
+
nlp_models=st.session_state.nlp_models,
|
| 523 |
+
semantic_t=t.get('SEMANTIC', {})
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
elif index == 4: # Discurso Vivo
|
| 527 |
+
st.session_state.tab_states['discourse_live_active'] = True
|
| 528 |
+
display_discourse_live_interface(
|
| 529 |
+
lang_code=st.session_state.lang_code,
|
| 530 |
+
nlp_models=st.session_state.nlp_models,
|
| 531 |
+
discourse_t=t.get('DISCOURSE', {})
|
| 532 |
+
)
|
| 533 |
+
|
| 534 |
+
elif index == 5: # Discurso
|
| 535 |
+
st.session_state.tab_states['discourse_active'] = True
|
| 536 |
+
display_discourse_interface(
|
| 537 |
+
lang_code=st.session_state.lang_code,
|
| 538 |
+
nlp_models=st.session_state.nlp_models,
|
| 539 |
+
discourse_t=t.get('DISCOURSE', {})
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
+
elif index == 6: # Actividades
|
| 543 |
+
st.session_state.tab_states['activities_active'] = True
|
| 544 |
+
display_student_activities(
|
| 545 |
+
username=st.session_state.username,
|
| 546 |
+
lang_code=st.session_state.lang_code,
|
| 547 |
+
t=t.get('ACTIVITIES', {})
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
elif index == 7: # Feedback
|
| 551 |
+
st.session_state.tab_states['feedback_active'] = True
|
| 552 |
+
display_feedback_form(
|
| 553 |
+
lang_code=st.session_state.lang_code,
|
| 554 |
+
t=t.get('FEEDBACK', {})
|
| 555 |
+
)
|
| 556 |
|
| 557 |
+
except Exception as e:
|
| 558 |
+
# Desactivar el estado en caso de error
|
| 559 |
+
state_key = get_state_key_for_index(index)
|
| 560 |
+
if state_key:
|
| 561 |
+
st.session_state.tab_states[state_key] = False
|
| 562 |
+
logger.error(f"Error en tab {index}: {str(e)}")
|
| 563 |
+
st.error(t.get('tab_error', 'Error al cargar esta sección'))
|
| 564 |
+
|
| 565 |
+
# Funciones auxiliares para manejar los estados de los tabs
|
| 566 |
+
def get_tab_index(state_key):
|
| 567 |
+
"""Obtiene el índice del tab basado en la clave de estado"""
|
| 568 |
+
index_map = {
|
| 569 |
+
'current_situation_active': 0,
|
| 570 |
+
'morpho_active': 1,
|
| 571 |
+
'semantic_live_active': 2,
|
| 572 |
+
'semantic_active': 3,
|
| 573 |
+
'discourse_live_active': 4,
|
| 574 |
+
'discourse_active': 5,
|
| 575 |
+
'activities_active': 6,
|
| 576 |
+
'feedback_active': 7
|
| 577 |
+
}
|
| 578 |
+
return index_map.get(state_key, -1)
|
| 579 |
+
|
| 580 |
+
def get_state_key_for_index(index):
|
| 581 |
+
"""Obtiene la clave de estado basada en el índice del tab"""
|
| 582 |
+
state_map = {
|
| 583 |
+
0: 'current_situation_active',
|
| 584 |
+
1: 'morpho_active',
|
| 585 |
+
2: 'semantic_live_active',
|
| 586 |
+
3: 'semantic_active',
|
| 587 |
+
4: 'discourse_live_active',
|
| 588 |
+
5: 'discourse_active',
|
| 589 |
+
6: 'activities_active',
|
| 590 |
+
7: 'feedback_active'
|
| 591 |
+
}
|
| 592 |
+
return state_map.get(index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
|
| 594 |
# Panel de depuración (solo visible en desarrollo)
|
| 595 |
if st.session_state.get('debug_mode', False):
|
|
|
|
| 601 |
st.write(f"Tab seleccionado: {st.session_state.selected_tab}")
|
| 602 |
st.write(f"Última actualización de datos: {st.session_state.get('last_data_fetch', 'Nunca')}")
|
| 603 |
|
| 604 |
+
####################################
|
| 605 |
########################################################################
|
| 606 |
def display_feedback_form(lang_code, t):
|
| 607 |
logging.info(f"display_feedback_form called with lang_code: {lang_code}")
|