AIdeaText commited on
Commit
a689749
verified
1 Parent(s): 9f4c5f9

Update modules/ui/ui.py

Browse files
Files changed (1) hide show
  1. modules/ui/ui.py +86 -224
modules/ui/ui.py CHANGED
@@ -368,232 +368,94 @@ def display_videos_and_info(lang_code, t):
368
  ####################################
369
  ####################################
370
 
371
- def user_page(lang_code, t):
372
- logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}")
373
-
374
- # Funciones auxiliares para manejar los estados de los tabs (movidas al inicio)
375
- def get_tab_index(state_key):
376
- """Obtiene el 铆ndice del tab basado en la clave de estado"""
377
- index_map = {
378
- 'current_situation_active': 0,
379
- 'morpho_active': 1,
380
- 'semantic_live_active': 2,
381
- 'semantic_active': 3,
382
- 'discourse_live_active': 4,
383
- 'discourse_active': 5,
384
- 'activities_active': 6,
385
- 'feedback_active': 7
386
- }
387
- return index_map.get(state_key, -1)
388
-
389
- def get_state_key_for_index(index):
390
- """Obtiene la clave de estado basada en el 铆ndice del tab"""
391
- state_map = {
392
- 0: 'current_situation_active',
393
- 1: 'morpho_active',
394
- 2: 'semantic_live_active',
395
- 3: 'semantic_active',
396
- 4: 'discourse_live_active',
397
- 5: 'discourse_active',
398
- 6: 'activities_active',
399
- 7: 'feedback_active'
400
- }
401
- return state_map.get(index)
402
-
403
- # Inicializar el tab seleccionado si no existe
404
- if 'selected_tab' not in st.session_state:
405
- st.session_state.selected_tab = 0
406
-
407
- # Inicializar el estado del an谩lisis en vivo
408
- if 'semantic_live_active' not in st.session_state:
409
- st.session_state.semantic_live_active = False
410
-
411
- # Manejar la carga inicial de datos del usuario
412
- if 'user_data' not in st.session_state:
413
- with st.spinner(t.get('loading_data', "Cargando tus datos...")):
414
- try:
415
- st.session_state.user_data = get_student_morphosyntax_data(st.session_state.username)
416
- st.session_state.last_data_fetch = datetime.now(timezone.utc).isoformat()
417
- except Exception as e:
418
- logger.error(f"Error al obtener datos del usuario: {str(e)}")
419
- st.error(t.get('data_load_error', "Hubo un problema al cargar tus datos. Por favor, intenta recargar la p谩gina."))
420
- return
421
-
422
- logger.info(f"Idioma actual: {st.session_state.lang_code}")
423
- logger.info(f"Modelos NLP cargados: {'nlp_models' in st.session_state}")
424
-
425
- # Registra las traducciones disponibles para depuraci贸n
426
- logger.info(f"Claves de traducci贸n disponibles: {list(t.keys())}")
427
-
428
- # Configuraci贸n de idiomas disponibles
429
- languages = {'Espa帽ol': 'es', 'Portugu锚s': 'pt', 'Fran莽ais': 'fr', 'English': 'en'}
430
-
431
- # Estilos CSS personalizados
432
- st.markdown("""
433
- <style>
434
- .stSelectbox > div > div {
435
- padding-top: 0px;
436
- }
437
- .stButton > button {
438
- padding-top: 2px;
439
- margin-top: 0px;
440
- }
441
- div[data-testid="stHorizontalBlock"] > div:nth-child(3) {
442
- display: flex;
443
- justify-content: flex-end;
444
- align-items: center;
445
- }
446
- </style>
447
- """, unsafe_allow_html=True)
448
-
449
- # Barra superior con informaci贸n del usuario y controles
450
- with st.container():
451
- col1, col2, col3 = st.columns([2, 2, 1])
452
- with col1:
453
- st.markdown(f"<h3 style='margin-bottom: 0; padding-top: 10px;'>{t.get('welcome', 'Bienvenido')}, {st.session_state.username}</h3>",
454
- unsafe_allow_html=True)
455
- with col2:
456
- selected_lang = st.selectbox(
457
- t.get('select_language', 'Seleccionar idioma'),
458
- list(languages.keys()),
459
- index=list(languages.values()).index(st.session_state.lang_code),
460
- key=f"language_selector_{st.session_state.username}_{st.session_state.lang_code}"
461
- )
462
- new_lang_code = languages[selected_lang]
463
- if st.session_state.lang_code != new_lang_code:
464
- st.session_state.lang_code = new_lang_code
465
- logger.info(f"Cambiando idioma de {st.session_state.lang_code} a {new_lang_code}")
466
- st.rerun()
467
- with col3:
468
- if st.button(t.get('logout', 'Cerrar sesi贸n'),
469
- key=f"logout_button_{st.session_state.username}_{st.session_state.lang_code}"):
470
- st.session_state.clear()
471
- st.rerun()
472
-
473
- st.markdown("---")
474
-
475
- # Asegurarse de que tenemos las traducciones del chatbot
476
- chatbot_t = t.get('CHATBOT_TRANSLATIONS', {})
477
-
478
- # Mostrar chatbot en sidebar
479
- display_sidebar_chat(lang_code, chatbot_t)
480
-
481
- # Inicializar estados para todos los tabs
482
- if 'tab_states' not in st.session_state:
483
- st.session_state.tab_states = {
484
- 'current_situation_active': False,
485
- 'morpho_active': False,
486
- 'semantic_live_active': False,
487
- 'semantic_active': False,
488
- 'discourse_live_active': False,
489
- 'discourse_active': False,
490
- 'activities_active': False,
491
- 'feedback_active': False
492
- }
493
-
494
- # Sistema de tabs
495
- tab_names = [
496
- t.get('TABS', {}).get('current_situation_tab', "Mi Situaci贸n Actual"),
497
- t.get('TABS', {}).get('morpho_tab', 'An谩lisis Morfosint谩ctico'),
498
- t.get('TABS', {}).get('semantic_live_tab', 'An谩lisis Sem谩ntico Vivo'),
499
- t.get('TABS', {}).get('semantic_tab', 'An谩lisis Sem谩ntico'),
500
- t.get('TABS', {}).get('discourse_live_tab', 'An谩lisis de Discurso Vivo'),
501
- t.get('TABS', {}).get('discourse_tab', 'An谩lsis de Discurso'),
502
- t.get('TABS', {}).get('activities_tab', 'Mis Actividades'),
503
- t.get('TABS', {}).get('feedback_tab', 'Formulario de Comentarios')
504
- ]
505
-
506
- # Log para depuraci贸n de traducciones de tabs
507
- logger.info(f"Tab names for {lang_code}: {tab_names}")
508
-
509
- # Crear tabs
510
- tabs = st.tabs(tab_names)
511
-
512
- # Manejar el contenido de cada tab
513
- for index, tab in enumerate(tabs):
514
- with tab:
515
- try:
516
- # Actualizar el tab seleccionado solo si no hay un an谩lisis activo
517
- if tab.selected and st.session_state.selected_tab != index:
518
- can_switch = True
519
- for state_key in st.session_state.tab_states.keys():
520
- if st.session_state.tab_states[state_key] and index != get_tab_index(state_key):
521
- can_switch = False
522
- break
523
- if can_switch:
524
- st.session_state.selected_tab = index
525
-
526
- if index == 0: # Situaci贸n actual
527
- st.session_state.tab_states['current_situation_active'] = True
528
- display_current_situation_interface(
529
- lang_code=st.session_state.lang_code,
530
- nlp_models=st.session_state.nlp_models,
531
- current_situation_t=t.get('CURRENT_SITUATION', {})
532
- )
533
-
534
- elif index == 1: # Morfosint谩ctico
535
- st.session_state.tab_states['morpho_active'] = True
536
- display_morphosyntax_interface(
537
- lang_code=st.session_state.lang_code,
538
- nlp_models=st.session_state.nlp_models,
539
- morpho_t=t.get('MORPHOSYNTACTIC', {})
540
- )
541
-
542
- elif index == 2: # Sem谩ntico Vivo
543
- st.session_state.tab_states['semantic_live_active'] = True
544
- display_semantic_live_interface(
545
- lang_code=st.session_state.lang_code,
546
- nlp_models=st.session_state.nlp_models,
547
- semantic_t=t.get('SEMANTIC', {})
548
- )
549
-
550
- elif index == 3: # Sem谩ntico
551
- st.session_state.tab_states['semantic_active'] = True
552
- display_semantic_interface(
553
- lang_code=st.session_state.lang_code,
554
- nlp_models=st.session_state.nlp_models,
555
- semantic_t=t.get('SEMANTIC', {})
556
- )
557
-
558
- elif index == 4: # Discurso Vivo
559
- st.session_state.tab_states['discourse_live_active'] = True
560
- display_discourse_live_interface(
561
- lang_code=st.session_state.lang_code,
562
- nlp_models=st.session_state.nlp_models,
563
- discourse_t=t.get('DISCOURSE', {})
564
- )
565
-
566
- elif index == 5: # Discurso
567
- st.session_state.tab_states['discourse_active'] = True
568
- display_discourse_interface(
569
- lang_code=st.session_state.lang_code,
570
- nlp_models=st.session_state.nlp_models,
571
- discourse_t=t.get('DISCOURSE', {})
572
- )
573
-
574
- elif index == 6: # Actividades
575
- st.session_state.tab_states['activities_active'] = True
576
- display_student_activities(
577
- username=st.session_state.username,
578
- lang_code=st.session_state.lang_code,
579
- t=t.get('ACTIVITIES', {})
580
- )
581
-
582
- elif index == 7: # Feedback
583
- st.session_state.tab_states['feedback_active'] = True
584
- display_feedback_form(
585
- lang_code=st.session_state.lang_code,
586
- t=t.get('FEEDBACK', {})
587
- )
588
 
589
- except Exception as e:
590
- # Desactivar el estado en caso de error
591
- state_key = get_state_key_for_index(index)
592
- if state_key:
593
- st.session_state.tab_states[state_key] = False
594
- logger.error(f"Error en tab {index}: {str(e)}")
595
- st.error(t.get('tab_error', 'Error al cargar esta secci贸n'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
596
 
 
 
 
597
  # Panel de depuraci贸n (solo visible en desarrollo)
598
  if st.session_state.get('debug_mode', False):
599
  with st.expander("Debug Info"):
 
368
  ####################################
369
  ####################################
370
 
371
+ # Manejar el contenido de cada tab
372
+ for index, tab in enumerate(tabs):
373
+ with tab:
374
+ try:
375
+ # Actualizar el tab seleccionado solo si no hay un an谩lisis activo
376
+ if tab.selected and st.session_state.selected_tab != index:
377
+ can_switch = True
378
+ for state_key in st.session_state.tab_states.keys():
379
+ if st.session_state.tab_states[state_key] and index != get_tab_index(state_key):
380
+ can_switch = False
381
+ break
382
+ if can_switch:
383
+ st.session_state.selected_tab = index
384
+
385
+ if index == 0: # Situaci贸n actual
386
+ st.session_state.tab_states['current_situation_active'] = True
387
+ display_current_situation_interface(
388
+ st.session_state.lang_code,
389
+ st.session_state.nlp_models,
390
+ t # Pasamos todo el diccionario de traducciones
391
+ )
392
+
393
+ elif index == 1: # Morfosint谩ctico
394
+ st.session_state.tab_states['morpho_active'] = True
395
+ display_morphosyntax_interface(
396
+ st.session_state.lang_code,
397
+ st.session_state.nlp_models,
398
+ t # Pasamos todo el diccionario de traducciones
399
+ )
400
+
401
+ elif index == 2: # Sem谩ntico Vivo
402
+ st.session_state.tab_states['semantic_live_active'] = True
403
+ display_semantic_live_interface(
404
+ st.session_state.lang_code,
405
+ st.session_state.nlp_models,
406
+ t # Pasamos todo el diccionario de traducciones
407
+ )
408
+
409
+ elif index == 3: # Sem谩ntico
410
+ st.session_state.tab_states['semantic_active'] = True
411
+ display_semantic_interface(
412
+ st.session_state.lang_code,
413
+ st.session_state.nlp_models,
414
+ t # Pasamos todo el diccionario de traducciones
415
+ )
416
+
417
+ elif index == 4: # Discurso Vivo
418
+ st.session_state.tab_states['discourse_live_active'] = True
419
+ display_discourse_live_interface(
420
+ st.session_state.lang_code,
421
+ st.session_state.nlp_models,
422
+ t # Pasamos todo el diccionario de traducciones
423
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
 
425
+ elif index == 5: # Discurso
426
+ st.session_state.tab_states['discourse_active'] = True
427
+ display_discourse_interface(
428
+ st.session_state.lang_code,
429
+ st.session_state.nlp_models,
430
+ t # Pasamos todo el diccionario de traducciones
431
+ )
432
+
433
+ elif index == 6: # Actividades
434
+ st.session_state.tab_states['activities_active'] = True
435
+ display_student_activities(
436
+ username=st.session_state.username,
437
+ lang_code=st.session_state.lang_code,
438
+ t=t # Pasamos todo el diccionario de traducciones
439
+ )
440
+
441
+ elif index == 7: # Feedback
442
+ st.session_state.tab_states['feedback_active'] = True
443
+ display_feedback_form(
444
+ st.session_state.lang_code,
445
+ t # Ya estaba recibiendo el diccionario completo
446
+ )
447
+
448
+ except Exception as e:
449
+ # Desactivar el estado en caso de error
450
+ state_key = get_state_key_for_index(index)
451
+ if state_key:
452
+ st.session_state.tab_states[state_key] = False
453
+ logger.error(f"Error en tab {index}: {str(e)}")
454
+ st.error(t.get('tab_error', 'Error al cargar esta secci贸n'))
455
 
456
+
457
+ #########################################################################################
458
+ #########################################################################################
459
  # Panel de depuraci贸n (solo visible en desarrollo)
460
  if st.session_state.get('debug_mode', False):
461
  with st.expander("Debug Info"):