Ubuntu commited on
Commit ·
3e912aa
1
Parent(s): 49d7f2c
feat: Simplify login page - Remove marketing content, show only logo and form
Browse files- Replace app.py with simplified version (app_simple_login.py)
- Remove carousel, tabs, videos, gallery
- Show only: Logo + Email + Password + Sign In button
- Backup saved as: app_backup_20260712_150747.py
- After login, full interface remains the same
- app.py +218 -111
- app_backup_20260712_150747.py +168 -0
app.py
CHANGED
|
@@ -1,168 +1,275 @@
|
|
| 1 |
-
# AIdeaText
|
| 2 |
-
#
|
|
|
|
| 3 |
import logging
|
| 4 |
import streamlit as st
|
| 5 |
import sys
|
| 6 |
import os
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
from PIL import Image
|
| 10 |
|
| 11 |
# Configuración básica
|
| 12 |
load_dotenv()
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
-
# Configuración
|
| 17 |
st.set_page_config(
|
| 18 |
-
page_title="AIdeaText",
|
| 19 |
-
layout="
|
| 20 |
-
initial_sidebar_state="collapsed"
|
| 21 |
)
|
| 22 |
|
| 23 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 24 |
|
| 25 |
-
# Importaciones locales
|
| 26 |
-
from translations import get_translations, get_landing_translations
|
| 27 |
from session_state import initialize_session_state
|
| 28 |
-
from modules.ui.ui import main as ui_main
|
| 29 |
from modules.utils.spacy_utils import load_spacy_models
|
| 30 |
-
from modules.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
create_admin_user,
|
| 56 |
-
update_student_user, # Agregada
|
| 57 |
-
delete_student_user, # Agregada
|
| 58 |
-
record_login,
|
| 59 |
-
record_logout,
|
| 60 |
-
get_recent_sessions,
|
| 61 |
-
get_user_total_time,
|
| 62 |
-
store_application_request,
|
| 63 |
-
store_student_feedback
|
| 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 |
-
delete_student
|
| 99 |
-
)
|
| 100 |
-
from modules.admin.admin_ui import admin_page
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
def app_main():
|
|
|
|
| 113 |
try:
|
| 114 |
-
logger.info("
|
| 115 |
|
| 116 |
# Inicializar el estado de la sesión
|
| 117 |
if 'initialized' not in st.session_state:
|
| 118 |
initialize_session_state()
|
| 119 |
st.session_state.initialized = True
|
| 120 |
|
| 121 |
-
# Inicializar conexiones a bases de datos
|
| 122 |
if 'db_initialized' not in st.session_state:
|
| 123 |
st.session_state.db_initialized = initialize_database_connections()
|
| 124 |
|
| 125 |
-
# Cargar modelos NLP
|
| 126 |
if 'nlp_models' not in st.session_state:
|
| 127 |
-
logger.info("Inicializando modelos NLP
|
| 128 |
st.session_state.nlp_models = initialize_nlp_models()
|
| 129 |
-
logger.info("Modelos NLP inicializados
|
| 130 |
-
|
| 131 |
-
#
|
| 132 |
-
if 'semantic_state' not in st.session_state:
|
| 133 |
-
st.session_state.semantic_state = {
|
| 134 |
-
'last_analysis': None,
|
| 135 |
-
'analysis_count': 0
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
if 'discourse_state' not in st.session_state:
|
| 139 |
-
st.session_state.discourse_state = {
|
| 140 |
-
'last_analysis': None,
|
| 141 |
-
'analysis_count': 0
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
# Configurar la página inicial si no está configurada
|
| 145 |
if 'page' not in st.session_state:
|
| 146 |
st.session_state.page = 'login'
|
| 147 |
|
| 148 |
-
# Prevenir reinicios innecesarios preservando el estado
|
| 149 |
-
if 'selected_tab' not in st.session_state:
|
| 150 |
-
st.session_state.selected_tab = 0
|
| 151 |
-
|
| 152 |
logger.info(f"Página actual: {st.session_state.page}")
|
| 153 |
-
logger.info(f"
|
| 154 |
|
| 155 |
-
#
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
except Exception as e:
|
| 160 |
logger.error(f"Error en app_main: {str(e)}", exc_info=True)
|
| 161 |
-
st.error("Se ha producido un error
|
| 162 |
-
if st.button("Reiniciar
|
| 163 |
-
key=generate_unique_key("app", "reset_button")):
|
| 164 |
st.session_state.clear()
|
| 165 |
st.rerun()
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
| 168 |
-
app_main()
|
|
|
|
| 1 |
+
# AIdeaText v5 - Simple Login Page
|
| 2 |
+
# app_simple_login.py - Página simplificada con solo logo y login
|
| 3 |
+
|
| 4 |
import logging
|
| 5 |
import streamlit as st
|
| 6 |
import sys
|
| 7 |
import os
|
| 8 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Configuración básica
|
| 11 |
load_dotenv()
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
# Configuración de la página
|
| 16 |
st.set_page_config(
|
| 17 |
+
page_title="AIdeaText - Login",
|
| 18 |
+
layout="centered",
|
| 19 |
+
initial_sidebar_state="collapsed"
|
| 20 |
)
|
| 21 |
|
| 22 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 23 |
|
| 24 |
+
# Importaciones locales necesarias
|
|
|
|
| 25 |
from session_state import initialize_session_state
|
|
|
|
| 26 |
from modules.utils.spacy_utils import load_spacy_models
|
| 27 |
+
from modules.database.database_init import initialize_database_connections
|
| 28 |
+
from modules.database.sql_db import get_user, record_login
|
| 29 |
+
from modules.ui.ui import user_page # Para después del login
|
| 30 |
+
from modules.admin.admin_ui import admin_page # Para administradores
|
| 31 |
+
from translations import get_translations
|
| 32 |
|
| 33 |
+
@st.cache_resource(show_spinner=False)
|
| 34 |
+
def initialize_nlp_models():
|
| 35 |
+
logger.info("Cargando modelos de spaCy")
|
| 36 |
+
models = load_spacy_models()
|
| 37 |
+
logger.info("Modelos de spaCy cargados exitosamente")
|
| 38 |
+
return models
|
| 39 |
|
| 40 |
+
def authenticate_user(username, password):
|
| 41 |
+
"""Autentica un usuario contra la base de datos"""
|
| 42 |
+
try:
|
| 43 |
+
user = get_user(username)
|
| 44 |
+
if user and user['password'] == password:
|
| 45 |
+
# Registrar login
|
| 46 |
+
record_login(username)
|
| 47 |
+
return True, user.get('role', 'Student')
|
| 48 |
+
return False, None
|
| 49 |
+
except Exception as e:
|
| 50 |
+
logger.error(f"Error en autenticación: {str(e)}")
|
| 51 |
+
return False, None
|
| 52 |
|
| 53 |
+
def simple_login_page():
|
| 54 |
+
"""Página simplificada con solo logo y login"""
|
| 55 |
|
| 56 |
+
# CSS personalizado para centrado y diseño limpio
|
| 57 |
+
st.markdown("""
|
| 58 |
+
<style>
|
| 59 |
+
/* Ocultar elementos default de Streamlit */
|
| 60 |
+
#MainMenu {visibility: hidden;}
|
| 61 |
+
footer {visibility: hidden;}
|
| 62 |
+
header {visibility: hidden;}
|
| 63 |
|
| 64 |
+
/* Contenedor principal */
|
| 65 |
+
.main {
|
| 66 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 67 |
+
min-height: 100vh;
|
| 68 |
+
display: flex;
|
| 69 |
+
align-items: center;
|
| 70 |
+
justify-content: center;
|
| 71 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
/* Card de login */
|
| 74 |
+
.login-container {
|
| 75 |
+
background: white;
|
| 76 |
+
padding: 40px;
|
| 77 |
+
border-radius: 20px;
|
| 78 |
+
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
| 79 |
+
max-width: 400px;
|
| 80 |
+
width: 100%;
|
| 81 |
+
margin: 0 auto;
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
/* Logo centrado */
|
| 85 |
+
.logo-container {
|
| 86 |
+
text-align: center;
|
| 87 |
+
margin-bottom: 30px;
|
| 88 |
+
}
|
| 89 |
|
| 90 |
+
.logo-container img {
|
| 91 |
+
max-width: 200px;
|
| 92 |
+
height: auto;
|
| 93 |
+
}
|
| 94 |
|
| 95 |
+
/* Título */
|
| 96 |
+
.login-title {
|
| 97 |
+
text-align: center;
|
| 98 |
+
color: #1E3A8A;
|
| 99 |
+
font-size: 1.8em;
|
| 100 |
+
font-weight: 700;
|
| 101 |
+
margin-bottom: 30px;
|
| 102 |
+
}
|
| 103 |
|
| 104 |
+
/* Inputs de Streamlit */
|
| 105 |
+
.stTextInput > div > div > input {
|
| 106 |
+
border-radius: 10px;
|
| 107 |
+
border: 2px solid #e5e7eb;
|
| 108 |
+
padding: 12px;
|
| 109 |
+
font-size: 16px;
|
| 110 |
+
}
|
| 111 |
|
| 112 |
+
.stTextInput > div > div > input:focus {
|
| 113 |
+
border-color: #667eea;
|
| 114 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
| 115 |
+
}
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
/* Botón de login */
|
| 118 |
+
.stButton > button {
|
| 119 |
+
width: 100%;
|
| 120 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 121 |
+
color: white;
|
| 122 |
+
border: none;
|
| 123 |
+
border-radius: 10px;
|
| 124 |
+
padding: 12px;
|
| 125 |
+
font-size: 16px;
|
| 126 |
+
font-weight: 600;
|
| 127 |
+
cursor: pointer;
|
| 128 |
+
transition: transform 0.2s;
|
| 129 |
+
}
|
| 130 |
|
| 131 |
+
.stButton > button:hover {
|
| 132 |
+
transform: translateY(-2px);
|
| 133 |
+
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/* Footer */
|
| 137 |
+
.footer-text {
|
| 138 |
+
text-align: center;
|
| 139 |
+
margin-top: 20px;
|
| 140 |
+
color: #6b7280;
|
| 141 |
+
font-size: 14px;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.footer-text a {
|
| 145 |
+
color: #667eea;
|
| 146 |
+
text-decoration: none;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.footer-text a:hover {
|
| 150 |
+
text-decoration: underline;
|
| 151 |
+
}
|
| 152 |
+
</style>
|
| 153 |
+
""", unsafe_allow_html=True)
|
| 154 |
+
|
| 155 |
+
# Contenedor de login
|
| 156 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 157 |
+
|
| 158 |
+
with col2:
|
| 159 |
+
# Logo
|
| 160 |
+
st.markdown("""
|
| 161 |
+
<div class="logo-container">
|
| 162 |
+
<img src="https://huggingface.co/spaces/AIdeaText/v5Prod/resolve/main/assets/img/Logo_300x300.png"
|
| 163 |
+
alt="AIdeaText Logo">
|
| 164 |
+
</div>
|
| 165 |
+
""", unsafe_allow_html=True)
|
| 166 |
+
|
| 167 |
+
# Título
|
| 168 |
+
st.markdown('<h1 class="login-title">Welcome to AIdeaText</h1>', unsafe_allow_html=True)
|
| 169 |
+
|
| 170 |
+
# Formulario de login
|
| 171 |
+
with st.form("login_form", clear_on_submit=False):
|
| 172 |
+
username = st.text_input(
|
| 173 |
+
"Email",
|
| 174 |
+
placeholder="your.email@university.edu",
|
| 175 |
+
key="login_email"
|
| 176 |
+
)
|
| 177 |
+
password = st.text_input(
|
| 178 |
+
"Password",
|
| 179 |
+
type="password",
|
| 180 |
+
placeholder="Enter your password",
|
| 181 |
+
key="login_password"
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
st.write("") # Espacio
|
| 185 |
+
submit_button = st.form_submit_button("🔐 Sign In")
|
| 186 |
+
|
| 187 |
+
# Procesar login
|
| 188 |
+
if submit_button:
|
| 189 |
+
if not username or not password:
|
| 190 |
+
st.error("⚠️ Please enter both email and password")
|
| 191 |
+
else:
|
| 192 |
+
with st.spinner("Authenticating..."):
|
| 193 |
+
success, role = authenticate_user(username, password)
|
| 194 |
+
|
| 195 |
+
if success:
|
| 196 |
+
st.session_state.logged_in = True
|
| 197 |
+
st.session_state.username = username
|
| 198 |
+
st.session_state.role = role
|
| 199 |
+
|
| 200 |
+
if role == 'Administrador':
|
| 201 |
+
st.session_state.page = 'Admin'
|
| 202 |
+
else:
|
| 203 |
+
st.session_state.page = 'user'
|
| 204 |
+
|
| 205 |
+
logger.info(f"Usuario autenticado: {username}, Rol: {role}")
|
| 206 |
+
st.success("✅ Login successful!")
|
| 207 |
+
st.rerun()
|
| 208 |
+
else:
|
| 209 |
+
st.error("❌ Invalid email or password")
|
| 210 |
+
|
| 211 |
+
# Footer
|
| 212 |
+
st.markdown("""
|
| 213 |
+
<div class="footer-text">
|
| 214 |
+
Need access? <a href="https://aideatext.ai/#contact" target="_blank">Contact us</a><br>
|
| 215 |
+
<small>© 2026 AIdeaText. All rights reserved.</small>
|
| 216 |
+
</div>
|
| 217 |
+
""", unsafe_allow_html=True)
|
| 218 |
|
| 219 |
def app_main():
|
| 220 |
+
"""Función principal de la aplicación"""
|
| 221 |
try:
|
| 222 |
+
logger.info("Iniciando aplicación AIdeaText")
|
| 223 |
|
| 224 |
# Inicializar el estado de la sesión
|
| 225 |
if 'initialized' not in st.session_state:
|
| 226 |
initialize_session_state()
|
| 227 |
st.session_state.initialized = True
|
| 228 |
|
| 229 |
+
# Inicializar conexiones a bases de datos
|
| 230 |
if 'db_initialized' not in st.session_state:
|
| 231 |
st.session_state.db_initialized = initialize_database_connections()
|
| 232 |
|
| 233 |
+
# Cargar modelos NLP
|
| 234 |
if 'nlp_models' not in st.session_state:
|
| 235 |
+
logger.info("Inicializando modelos NLP")
|
| 236 |
st.session_state.nlp_models = initialize_nlp_models()
|
| 237 |
+
logger.info("Modelos NLP inicializados")
|
| 238 |
+
|
| 239 |
+
# Configurar página inicial
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
if 'page' not in st.session_state:
|
| 241 |
st.session_state.page = 'login'
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
logger.info(f"Página actual: {st.session_state.page}")
|
| 244 |
+
logger.info(f"Logged in: {st.session_state.get('logged_in', False)}")
|
| 245 |
|
| 246 |
+
# Routing
|
| 247 |
+
if not st.session_state.get('logged_in', False):
|
| 248 |
+
# Mostrar página de login simple
|
| 249 |
+
simple_login_page()
|
| 250 |
+
elif st.session_state.page == 'user':
|
| 251 |
+
# Usuario autenticado - mostrar interfaz completa
|
| 252 |
+
if st.session_state.role == 'Administrador':
|
| 253 |
+
st.session_state.page = 'Admin'
|
| 254 |
+
st.rerun()
|
| 255 |
+
else:
|
| 256 |
+
lang_code = st.session_state.get('lang_code', 'en')
|
| 257 |
+
t = get_translations(lang_code)
|
| 258 |
+
user_page(lang_code, t)
|
| 259 |
+
elif st.session_state.page == 'Admin':
|
| 260 |
+
# Página de administrador
|
| 261 |
+
admin_page()
|
| 262 |
+
else:
|
| 263 |
+
logger.error(f"Página no reconocida: {st.session_state.page}")
|
| 264 |
+
st.session_state.page = 'login'
|
| 265 |
+
st.rerun()
|
| 266 |
|
| 267 |
except Exception as e:
|
| 268 |
logger.error(f"Error en app_main: {str(e)}", exc_info=True)
|
| 269 |
+
st.error("Se ha producido un error. Por favor, inténtelo de nuevo.")
|
| 270 |
+
if st.button("Reiniciar"):
|
|
|
|
| 271 |
st.session_state.clear()
|
| 272 |
st.rerun()
|
| 273 |
|
| 274 |
if __name__ == "__main__":
|
| 275 |
+
app_main()
|
app_backup_20260712_150747.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AIdeaText v3
|
| 2 |
+
# app.py
|
| 3 |
+
import logging
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
# Configuración básica
|
| 12 |
+
load_dotenv()
|
| 13 |
+
logging.basicConfig(level=logging.INFO)
|
| 14 |
+
logger = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
# Configuración básica de la página
|
| 17 |
+
st.set_page_config(
|
| 18 |
+
page_title="AIdeaText",
|
| 19 |
+
layout="wide",
|
| 20 |
+
initial_sidebar_state="collapsed" # Para dar más espacio al logo
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 24 |
+
|
| 25 |
+
# Importaciones locales
|
| 26 |
+
from translations import get_translations, get_landing_translations
|
| 27 |
+
from session_state import initialize_session_state
|
| 28 |
+
from modules.ui.ui import main as ui_main
|
| 29 |
+
from modules.utils.spacy_utils import load_spacy_models
|
| 30 |
+
from modules.utils.widget_utils import generate_unique_key
|
| 31 |
+
|
| 32 |
+
# Importaciones de interfaces
|
| 33 |
+
from modules.semantic.semantic_interface import (
|
| 34 |
+
display_semantic_interface,
|
| 35 |
+
display_semantic_results
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
from modules.discourse.discourse_interface import (
|
| 39 |
+
display_discourse_interface,
|
| 40 |
+
display_discourse_results
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Importaciones de base de datos
|
| 44 |
+
|
| 45 |
+
from modules.database.database_init import initialize_database_connections
|
| 46 |
+
|
| 47 |
+
from modules.database.sql_db import (
|
| 48 |
+
get_user,
|
| 49 |
+
get_admin_user,
|
| 50 |
+
get_student_user,
|
| 51 |
+
get_teacher_user,
|
| 52 |
+
create_user,
|
| 53 |
+
create_student_user,
|
| 54 |
+
create_teacher_user,
|
| 55 |
+
create_admin_user,
|
| 56 |
+
update_student_user, # Agregada
|
| 57 |
+
delete_student_user, # Agregada
|
| 58 |
+
record_login,
|
| 59 |
+
record_logout,
|
| 60 |
+
get_recent_sessions,
|
| 61 |
+
get_user_total_time,
|
| 62 |
+
store_application_request,
|
| 63 |
+
store_student_feedback
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
from modules.database.mongo_db import (
|
| 67 |
+
get_collection,
|
| 68 |
+
insert_document,
|
| 69 |
+
find_documents,
|
| 70 |
+
update_document,
|
| 71 |
+
delete_document
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
###########SEMANTIC
|
| 75 |
+
from modules.database.semantic_mongo_db import (
|
| 76 |
+
store_student_semantic_result,
|
| 77 |
+
get_student_semantic_analysis
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
from modules.database.discourse_mongo_db import (
|
| 81 |
+
store_student_discourse_result,
|
| 82 |
+
get_student_discourse_analysis
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
from modules.database.chat_mongo_db import (
|
| 86 |
+
store_chat_history,
|
| 87 |
+
get_chat_history
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# Importaciones de base de datos
|
| 91 |
+
from modules.studentact.student_activities_v2 import display_student_activities
|
| 92 |
+
# from modules.studentact.current_situation_interface import display_current_situation_interface
|
| 93 |
+
|
| 94 |
+
from modules.auth.auth import (
|
| 95 |
+
authenticate_student,
|
| 96 |
+
register_student,
|
| 97 |
+
update_student_info,
|
| 98 |
+
delete_student
|
| 99 |
+
)
|
| 100 |
+
from modules.admin.admin_ui import admin_page
|
| 101 |
+
|
| 102 |
+
logging.basicConfig(level=logging.INFO)
|
| 103 |
+
logger = logging.getLogger(__name__)
|
| 104 |
+
|
| 105 |
+
@st.cache_resource(show_spinner=False)
|
| 106 |
+
def initialize_nlp_models():
|
| 107 |
+
logger.info("Cargando modelos de spaCy")
|
| 108 |
+
models = load_spacy_models()
|
| 109 |
+
logger.info("Modelos de spaCy cargados exitosamente")
|
| 110 |
+
return models
|
| 111 |
+
|
| 112 |
+
def app_main():
|
| 113 |
+
try:
|
| 114 |
+
logger.info("Entrando en app_main()")
|
| 115 |
+
|
| 116 |
+
# Inicializar el estado de la sesión
|
| 117 |
+
if 'initialized' not in st.session_state:
|
| 118 |
+
initialize_session_state()
|
| 119 |
+
st.session_state.initialized = True
|
| 120 |
+
|
| 121 |
+
# Inicializar conexiones a bases de datos si no se ha hecho
|
| 122 |
+
if 'db_initialized' not in st.session_state:
|
| 123 |
+
st.session_state.db_initialized = initialize_database_connections()
|
| 124 |
+
|
| 125 |
+
# Cargar modelos NLP si no se ha hecho
|
| 126 |
+
if 'nlp_models' not in st.session_state:
|
| 127 |
+
logger.info("Inicializando modelos NLP en la sesión")
|
| 128 |
+
st.session_state.nlp_models = initialize_nlp_models()
|
| 129 |
+
logger.info("Modelos NLP inicializados y almacenados en la sesión")
|
| 130 |
+
|
| 131 |
+
# Inicializar estados de análisis si no existen
|
| 132 |
+
if 'semantic_state' not in st.session_state:
|
| 133 |
+
st.session_state.semantic_state = {
|
| 134 |
+
'last_analysis': None,
|
| 135 |
+
'analysis_count': 0
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if 'discourse_state' not in st.session_state:
|
| 139 |
+
st.session_state.discourse_state = {
|
| 140 |
+
'last_analysis': None,
|
| 141 |
+
'analysis_count': 0
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
# Configurar la página inicial si no está configurada
|
| 145 |
+
if 'page' not in st.session_state:
|
| 146 |
+
st.session_state.page = 'login'
|
| 147 |
+
|
| 148 |
+
# Prevenir reinicios innecesarios preservando el estado
|
| 149 |
+
if 'selected_tab' not in st.session_state:
|
| 150 |
+
st.session_state.selected_tab = 0
|
| 151 |
+
|
| 152 |
+
logger.info(f"Página actual: {st.session_state.page}")
|
| 153 |
+
logger.info(f"Rol del usuario: {st.session_state.role}")
|
| 154 |
+
|
| 155 |
+
# Dirigir el flujo a la interfaz de usuario principal
|
| 156 |
+
logger.info(f"Llamando a ui_main() desde app_main()")
|
| 157 |
+
ui_main()
|
| 158 |
+
|
| 159 |
+
except Exception as e:
|
| 160 |
+
logger.error(f"Error en app_main: {str(e)}", exc_info=True)
|
| 161 |
+
st.error("Se ha producido un error en la aplicación. Por favor, inténtelo de nuevo más tarde.")
|
| 162 |
+
if st.button("Reiniciar aplicación",
|
| 163 |
+
key=generate_unique_key("app", "reset_button")):
|
| 164 |
+
st.session_state.clear()
|
| 165 |
+
st.rerun()
|
| 166 |
+
|
| 167 |
+
if __name__ == "__main__":
|
| 168 |
+
app_main()
|