Spaces:
Sleeping
Sleeping
Update modules/ui/ui.py
Browse files- modules/ui/ui.py +57 -60
modules/ui/ui.py
CHANGED
|
@@ -214,24 +214,20 @@ def display_videos_and_info(lang_code, t):
|
|
| 214 |
""")
|
| 215 |
|
| 216 |
#Despu茅s de iniciar sesi贸n
|
| 217 |
-
|
| 218 |
def user_page(lang_code, t):
|
| 219 |
logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}")
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
if last_fetch_time:
|
| 225 |
-
last_fetch_time = parse(last_fetch_time)
|
| 226 |
-
else:
|
| 227 |
-
last_fetch_time = datetime.min.replace(tzinfo=timezone.utc)
|
| 228 |
|
| 229 |
-
#
|
| 230 |
-
if 'user_data' not in st.session_state
|
| 231 |
with st.spinner(t.get('loading_data', "Cargando tus datos...")):
|
| 232 |
try:
|
| 233 |
st.session_state.user_data = get_student_morphosyntax_data(st.session_state.username)
|
| 234 |
-
st.session_state.last_data_fetch =
|
| 235 |
except Exception as e:
|
| 236 |
logger.error(f"Error al obtener datos del usuario: {str(e)}")
|
| 237 |
st.error(t.get('data_load_error', "Hubo un problema al cargar tus datos. Por favor, intenta recargar la p谩gina."))
|
|
@@ -240,9 +236,10 @@ def user_page(lang_code, t):
|
|
| 240 |
logger.info(f"Idioma actual: {st.session_state.lang_code}")
|
| 241 |
logger.info(f"Modelos NLP cargados: {'nlp_models' in st.session_state}")
|
| 242 |
|
|
|
|
| 243 |
languages = {'Espa帽ol': 'es', 'English': 'en', 'Fran莽ais': 'fr'}
|
| 244 |
|
| 245 |
-
# Estilos CSS personalizados
|
| 246 |
st.markdown("""
|
| 247 |
<style>
|
| 248 |
.stSelectbox > div > div {
|
|
@@ -260,10 +257,12 @@ def user_page(lang_code, t):
|
|
| 260 |
</style>
|
| 261 |
""", unsafe_allow_html=True)
|
| 262 |
|
|
|
|
| 263 |
with st.container():
|
| 264 |
col1, col2, col3 = st.columns([2, 2, 1])
|
| 265 |
with col1:
|
| 266 |
-
st.markdown(f"<h3 style='margin-bottom: 0; padding-top: 10px;'>{t['welcome']}, {st.session_state.username}</h3>",
|
|
|
|
| 267 |
with col2:
|
| 268 |
selected_lang = st.selectbox(
|
| 269 |
t['select_language'],
|
|
@@ -276,22 +275,14 @@ def user_page(lang_code, t):
|
|
| 276 |
st.session_state.lang_code = new_lang_code
|
| 277 |
st.rerun()
|
| 278 |
with col3:
|
| 279 |
-
if st.button(t['logout'],
|
| 280 |
-
|
| 281 |
-
st.
|
| 282 |
-
|
| 283 |
-
# Reinicializar el estado de la sesi贸n
|
| 284 |
-
initialize_session_state()
|
| 285 |
-
|
| 286 |
-
# Recargar la aplicaci贸n
|
| 287 |
st.rerun()
|
| 288 |
|
| 289 |
st.markdown("---")
|
| 290 |
|
| 291 |
-
#
|
| 292 |
-
selected_tab = st.session_state.get('selected_tab', 0)
|
| 293 |
-
|
| 294 |
-
# Definir los tabs una sola vez
|
| 295 |
tabs = st.tabs([
|
| 296 |
t.get('morpho_tab', 'An谩lisis Morfosint谩ctico'),
|
| 297 |
t.get('semantic_tab', 'An谩lisis Sem谩ntico'),
|
|
@@ -299,41 +290,47 @@ def user_page(lang_code, t):
|
|
| 299 |
t.get('feedback_tab', 'Formulario de Comentarios')
|
| 300 |
])
|
| 301 |
|
| 302 |
-
#
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
st.
|
| 335 |
-
|
| 336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
def display_feedback_form(lang_code, t):
|
| 338 |
logging.info(f"display_feedback_form called with lang_code: {lang_code}")
|
| 339 |
|
|
|
|
| 214 |
""")
|
| 215 |
|
| 216 |
#Despu茅s de iniciar sesi贸n
|
| 217 |
+
####################################
|
| 218 |
def user_page(lang_code, t):
|
| 219 |
logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}")
|
| 220 |
|
| 221 |
+
# Inicializar el tab seleccionado si no existe
|
| 222 |
+
if 'selected_tab' not in st.session_state:
|
| 223 |
+
st.session_state.selected_tab = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
+
# Manejar la carga inicial de datos del usuario
|
| 226 |
+
if 'user_data' not in st.session_state:
|
| 227 |
with st.spinner(t.get('loading_data', "Cargando tus datos...")):
|
| 228 |
try:
|
| 229 |
st.session_state.user_data = get_student_morphosyntax_data(st.session_state.username)
|
| 230 |
+
st.session_state.last_data_fetch = datetime.now(timezone.utc).isoformat()
|
| 231 |
except Exception as e:
|
| 232 |
logger.error(f"Error al obtener datos del usuario: {str(e)}")
|
| 233 |
st.error(t.get('data_load_error', "Hubo un problema al cargar tus datos. Por favor, intenta recargar la p谩gina."))
|
|
|
|
| 236 |
logger.info(f"Idioma actual: {st.session_state.lang_code}")
|
| 237 |
logger.info(f"Modelos NLP cargados: {'nlp_models' in st.session_state}")
|
| 238 |
|
| 239 |
+
# Configuraci贸n de idiomas disponibles
|
| 240 |
languages = {'Espa帽ol': 'es', 'English': 'en', 'Fran莽ais': 'fr'}
|
| 241 |
|
| 242 |
+
# Estilos CSS personalizados
|
| 243 |
st.markdown("""
|
| 244 |
<style>
|
| 245 |
.stSelectbox > div > div {
|
|
|
|
| 257 |
</style>
|
| 258 |
""", unsafe_allow_html=True)
|
| 259 |
|
| 260 |
+
# Barra superior con informaci贸n del usuario y controles
|
| 261 |
with st.container():
|
| 262 |
col1, col2, col3 = st.columns([2, 2, 1])
|
| 263 |
with col1:
|
| 264 |
+
st.markdown(f"<h3 style='margin-bottom: 0; padding-top: 10px;'>{t['welcome']}, {st.session_state.username}</h3>",
|
| 265 |
+
unsafe_allow_html=True)
|
| 266 |
with col2:
|
| 267 |
selected_lang = st.selectbox(
|
| 268 |
t['select_language'],
|
|
|
|
| 275 |
st.session_state.lang_code = new_lang_code
|
| 276 |
st.rerun()
|
| 277 |
with col3:
|
| 278 |
+
if st.button(t['logout'],
|
| 279 |
+
key=f"logout_button_{st.session_state.username}_{st.session_state.lang_code}"):
|
| 280 |
+
st.session_state.clear()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
st.rerun()
|
| 282 |
|
| 283 |
st.markdown("---")
|
| 284 |
|
| 285 |
+
# Sistema de tabs
|
|
|
|
|
|
|
|
|
|
| 286 |
tabs = st.tabs([
|
| 287 |
t.get('morpho_tab', 'An谩lisis Morfosint谩ctico'),
|
| 288 |
t.get('semantic_tab', 'An谩lisis Sem谩ntico'),
|
|
|
|
| 290 |
t.get('feedback_tab', 'Formulario de Comentarios')
|
| 291 |
])
|
| 292 |
|
| 293 |
+
# Manejar el contenido de cada tab
|
| 294 |
+
for index, tab in enumerate(tabs):
|
| 295 |
+
if tab.selected:
|
| 296 |
+
st.session_state.selected_tab = index
|
| 297 |
+
|
| 298 |
+
with tab:
|
| 299 |
+
if index == 0:
|
| 300 |
+
display_morphosyntax_interface(
|
| 301 |
+
st.session_state.lang_code,
|
| 302 |
+
st.session_state.nlp_models,
|
| 303 |
+
t.get('TRANSLATIONS', {})
|
| 304 |
+
)
|
| 305 |
+
elif index == 1:
|
| 306 |
+
display_semantic_interface(
|
| 307 |
+
st.session_state.lang_code,
|
| 308 |
+
st.session_state.nlp_models,
|
| 309 |
+
t.get('TRANSLATIONS', {})
|
| 310 |
+
)
|
| 311 |
+
elif index == 2:
|
| 312 |
+
if st.session_state.user_data:
|
| 313 |
+
display_student_progress(
|
| 314 |
+
st.session_state.username,
|
| 315 |
+
st.session_state.lang_code,
|
| 316 |
+
t
|
| 317 |
+
)
|
| 318 |
+
else:
|
| 319 |
+
st.warning(t.get('no_data_warning', 'No se encontraron datos para este estudiante.'))
|
| 320 |
+
elif index == 3:
|
| 321 |
+
display_feedback_form(st.session_state.lang_code, t)
|
| 322 |
+
|
| 323 |
+
# Panel de depuraci贸n (solo visible en desarrollo)
|
| 324 |
+
if st.session_state.get('debug_mode', False):
|
| 325 |
+
with st.expander("Debug Info"):
|
| 326 |
+
st.write(f"P谩gina actual: {st.session_state.page}")
|
| 327 |
+
st.write(f"Usuario: {st.session_state.get('username', 'No logueado')}")
|
| 328 |
+
st.write(f"Rol: {st.session_state.get('role', 'No definido')}")
|
| 329 |
+
st.write(f"Idioma: {st.session_state.lang_code}")
|
| 330 |
+
st.write(f"Tab seleccionado: {st.session_state.selected_tab}")
|
| 331 |
+
st.write(f"脷ltima actualizaci贸n de datos: {st.session_state.get('last_data_fetch', 'Nunca')}")
|
| 332 |
+
|
| 333 |
+
########################################################################
|
| 334 |
def display_feedback_form(lang_code, t):
|
| 335 |
logging.info(f"display_feedback_form called with lang_code: {lang_code}")
|
| 336 |
|