|
|
|
|
|
import logging
|
|
import streamlit as st
|
|
import sys
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from datetime import datetime
|
|
|
|
def setup_logging():
|
|
log_dir = 'logs'
|
|
if not os.path.exists(log_dir):
|
|
os.makedirs(log_dir)
|
|
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
log_filename = f'{log_dir}/app_log_{current_time}.txt'
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
filename=log_filename,
|
|
filemode='w'
|
|
)
|
|
console = logging.StreamHandler()
|
|
console.setLevel(logging.INFO)
|
|
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
|
|
console.setFormatter(formatter)
|
|
logging.getLogger('').addHandler(console)
|
|
logging.info(f"Logging iniciado. Archivo de log: {log_filename}")
|
|
|
|
setup_logging()
|
|
load_dotenv()
|
|
|
|
st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
from translations import get_translations
|
|
|
|
from session_state import initialize_session_state
|
|
|
|
from modules.ui.ui import main as ui_main
|
|
|
|
from modules.utils.spacy_utils import load_spacy_models
|
|
|
|
from modules.morphosyntax.morphosyntax_interface import (
|
|
display_morphosyntax_interface
|
|
)
|
|
|
|
|
|
from modules.database.database_init import (
|
|
initialize_database_connections
|
|
)
|
|
|
|
from modules.database.sql_db import (
|
|
create_student_user,
|
|
get_student_user,
|
|
update_student_user,
|
|
delete_student_user,
|
|
store_application_request,
|
|
store_student_feedback
|
|
)
|
|
|
|
|
|
from modules.database.mongo_db import (
|
|
get_collection,
|
|
insert_document,
|
|
find_documents,
|
|
update_document,
|
|
delete_document
|
|
)
|
|
|
|
from modules.database.morphosintax_mongo_db import (
|
|
store_student_morphosyntax_result,
|
|
get_student_morphosyntax_analysis
|
|
)
|
|
|
|
from modules.database.chat_db import (
|
|
store_chat_history,
|
|
get_chat_history
|
|
)
|
|
|
|
from modules.studentact.student_activities_v2 import (
|
|
display_student_progress
|
|
)
|
|
|
|
from modules.auth.auth import (
|
|
authenticate_student,
|
|
register_student,
|
|
update_student_info,
|
|
delete_student
|
|
)
|
|
|
|
from modules.admin.admin_ui import admin_page
|
|
|
|
from modules.chatbot.chatbot import (
|
|
initialize_chatbot,
|
|
process_chat_input
|
|
)
|
|
|
|
print("Configurando p谩gina")
|
|
st.cache_data.clear()
|
|
st.cache_resource.clear()
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
@st.cache_resource
|
|
def initialize_nlp_models():
|
|
logger.info("Cargando modelos de spaCy")
|
|
models = load_spacy_models()
|
|
logger.info("Modelos de spaCy cargados exitosamente")
|
|
return models
|
|
|
|
def app_main():
|
|
try:
|
|
logger.info("Entrando en app_main()")
|
|
|
|
|
|
initialize_session_state()
|
|
|
|
|
|
if 'db_initialized' not in st.session_state:
|
|
st.session_state.db_initialized = initialize_database_connections()
|
|
|
|
|
|
if 'nlp_models' not in st.session_state:
|
|
logger.info("Inicializando modelos NLP en la sesi贸n")
|
|
st.session_state.nlp_models = initialize_nlp_models()
|
|
logger.info("Modelos NLP inicializados y almacenados en la sesi贸n")
|
|
|
|
|
|
if 'page' not in st.session_state:
|
|
st.session_state.page = 'login'
|
|
|
|
logger.info(f"P谩gina actual: {st.session_state.page}")
|
|
logger.info(f"Rol del usuario: {st.session_state.role}")
|
|
|
|
|
|
logger.info(f"Llamando a ui_main() desde app_main()")
|
|
ui_main()
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error en app_main: {str(e)}", exc_info=True)
|
|
st.error("Se ha producido un error en la aplicaci贸n. Por favor, int茅ntelo de nuevo m谩s tarde.")
|
|
if st.button("Reiniciar aplicaci贸n"):
|
|
st.rerun()
|
|
|
|
if __name__ == "__main__":
|
|
print("Llamando a app_main()")
|
|
app_main() |