File size: 7,773 Bytes
fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 8990058 fa1b8f7 8990058 fa1b8f7 bcf6759 34251f8 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 1ed39cd 37d04dc bcf6759 1ed39cd bcf6759 1ed39cd 101c049 1ed39cd fa1b8f7 bcf6759 1ed39cd bcf6759 5aa4b6b bcf6759 acaf933 bafc827 fa1b8f7 bcf6759 031ef50 bafc827 01663e9 bafc827 fa1b8f7 bcf6759 031ef50 ed94f48 031ef50 01663e9 031ef50 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bafc827 fa1b8f7 bafc827 031ef50 fa1b8f7 bafc827 101c049 bcf6759 1ed39cd bcf6759 fa1b8f7 bcf6759 fa1b8f7 101c049 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 fa1b8f7 bcf6759 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | # modules/ui/ui.py
import streamlit as st
import logging
# Configurar logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Importaciones locales
from session_state import initialize_session_state, logout
from translations import get_translations
from ..auth.auth import authenticate_user
from ..admin.admin_ui import admin_page
# Intento de importación con logger
try:
from .user_page import user_page
except ImportError as e:
logger.error(f"No se pudo importar user_page: {str(e)}")
def user_page(lang_code, t):
st.error("La página de usuario no está disponible.")
#############################################################
def main():
# Inicializar session_state si no existe
if 'page' not in st.session_state:
st.session_state.page = 'login'
logger.info(f"Entrando en main() - Página actual: {st.session_state.page}")
# Configurar inglés como idioma por defecto
if 'lang_code' not in st.session_state:
st.session_state.lang_code = 'en'
lang_code = st.session_state.get('lang_code', 'en')
t = get_translations(lang_code)
if st.session_state.get('logged_out', False):
st.session_state.logged_out = False
st.session_state.page = 'login'
st.rerun()
if not st.session_state.get('logged_in', False):
logger.info("Usuario no ha iniciado sesión. Mostrando página de login")
login_page(lang_code, t)
elif st.session_state.page == 'user':
if st.session_state.role == 'Administrador':
logger.info("Redirigiendo a la página de administrador")
st.session_state.page = 'Admin'
st.rerun()
else:
logger.info("Renderizando página de usuario")
user_page(lang_code, t)
elif st.session_state.page == "Admin":
logger.info("Renderizando página de administrador")
admin_page()
else:
logger.error(f"Página no reconocida: {st.session_state.page}")
st.error(t.get('unrecognized_page', 'Página no reconocida'))
st.session_state.page = 'user'
st.rerun()
#############################################################
def login_page(lang_code, t):
# CSS personalizado
st.markdown("""
<style>
/* Ocultar header y footer de Streamlit */
#MainMenu {visibility: hidden !important;}
footer {visibility: hidden !important;}
header {visibility: hidden !important;}
.stDeployButton {display: none !important;}
[data-testid="stHeader"] {display: none !important;}
[data-testid="stToolbar"] {display: none !important;}
[data-testid="stDecoration"] {display: none !important;}
[data-testid="stStatusWidget"] {display: none !important;}
section[data-testid="stSidebar"] {display: none !important;}
/* Ocultar elemento superior derecho (rectángulo vacío) */
.stActionButton {display: none !important;}
button[kind="header"] {display: none !important;}
/* Centrar contenido */
.main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
/* Container del login */
.login-container {
background: white;
padding: 3rem;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
max-width: 700px;
width: 100%;
margin: 0 auto;
text-align: center;
}
/* Logo AIdeaText */
.logo-aideatext {
width: 120px;
height: auto;
margin: 0 10px 2rem 0;
display: inline-block;
vertical-align: middle;
}
/* Logo NVIDIA (más grande) */
.logo-nvidia {
width: 300px;
height: auto;
margin: 0 0 2rem 10px;
display: inline-block;
vertical-align: middle;
}
/* Título */
.login-title {
text-align: center;
font-size: 1.8rem;
font-weight: 700;
color: #1f2937;
margin-bottom: 0.5rem;
}
.login-subtitle {
text-align: center;
font-size: 0.95rem;
color: #6b7280;
margin-bottom: 2rem;
}
/* Footer NVIDIA */
.nvidia-footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: rgba(255,255,255,0.95);
padding: 12px;
text-align: center;
font-size: 11px;
color: #6b7280;
border-top: 1px solid #e5e7eb;
backdrop-filter: blur(10px);
}
/* Botón de submit */
.stButton button {
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 0.75rem;
border-radius: 8px;
font-weight: 600;
font-size: 1rem;
margin-top: 1rem;
}
.stButton button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}
/* Inputs */
.stTextInput input {
border-radius: 8px;
border: 1px solid #d1d5db;
padding: 0.75rem;
}
.stTextInput input:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
</style>
""", unsafe_allow_html=True)
# Container principal con logos
st.markdown("""
<div class="login-container">
<img class="logo-aideatext" src="https://huggingface.co/spaces/AIdeaText/v5Prod/resolve/main/assets/img/AIdeaText_Logo_vectores.png" alt="AIdeaText Logo">
<img class="logo-nvidia" src="https://huggingface.co/spaces/AIdeaText/v5Prod/resolve/main/assets/img/socialmedia/nvidia/nvidia-inception-program-badge-rgb-for-screen.png" alt="NVIDIA Logo">
</div>
""", unsafe_allow_html=True)
# Título y subtítulo
st.markdown("""
<h1 class="login-title">AIdeaText</h1>
<p class="login-subtitle">Cognitive Development Platform</p>
""", unsafe_allow_html=True)
# Formulario de login
with st.form("login_form", clear_on_submit=False):
username = st.text_input("Email", placeholder="your.email@institution.edu")
password = st.text_input("Password", type="password", placeholder="Enter your password")
submit_button = st.form_submit_button("Sign In")
if submit_button:
success, role = authenticate_user(username, password)
if success:
st.session_state.logged_in = True
st.session_state.username = username
st.session_state.role = role
if role == 'Administrador':
st.session_state.page = 'Admin'
else:
st.session_state.page = 'user'
logger.info(f"Usuario autenticado: {username}, Rol: {role}")
st.rerun()
else:
st.error("❌ Invalid credentials. Please try again.")
# Footer NVIDIA
st.markdown("""
<div class="nvidia-footer">
© 2025 NVIDIA, the NVIDIA logo are trademarks and/or registered trademarks of NVIDIA Corporation in the U.S. and other countries.
</div>
""", unsafe_allow_html=True)
#############################################################
__all__ = ['main', 'login_page', 'initialize_session_state']
if __name__ == "__main__":
main()
|