|
|
|
|
|
import logging |
|
import streamlit as st |
|
import sys |
|
import os |
|
from dotenv import load_dotenv |
|
from datetime import datetime |
|
from PIL import Image |
|
|
|
|
|
|
|
load_dotenv() |
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
|
ASSETS_DIR = os.path.join(ROOT_DIR, 'assets', 'img') |
|
LOGO_PATH = os.path.join(ASSETS_DIR, 'aideaText_logo.png') |
|
ICON_PATH = os.path.join(ASSETS_DIR, 'aideaText.ico') |
|
|
|
def load_assets(): |
|
""" |
|
Carga los archivos de imágenes necesarios |
|
""" |
|
try: |
|
|
|
if os.path.exists(ICON_PATH): |
|
icon = Image.open(ICON_PATH) |
|
else: |
|
icon = "🧠" |
|
logger.warning("Archivo de ícono no encontrado") |
|
|
|
return icon |
|
except Exception as e: |
|
logger.error(f"Error cargando assets: {str(e)}") |
|
return "🧠" |
|
|
|
|
|
page_icon = load_assets() |
|
|
|
|
|
st.set_page_config( |
|
page_title="AIdeaText", |
|
layout="wide", |
|
page_icon=page_icon, |
|
initial_sidebar_state="expanded" |
|
) |
|
|
|
|
|
def setup_logo(): |
|
""" |
|
Configura el logo en la interfaz |
|
""" |
|
try: |
|
if os.path.exists(LOGO_PATH): |
|
st.logo( |
|
image=LOGO_PATH, |
|
icon_image=LOGO_PATH, |
|
size="medium", |
|
link="https://aideatext.ai" |
|
) |
|
return True |
|
else: |
|
logger.warning("Archivo de logo no encontrado") |
|
return False |
|
except Exception as e: |
|
logger.error(f"Error configurando logo: {str(e)}") |
|
return False |
|
|
|
|
|
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.utils.widget_utils import generate_unique_key |
|
|
|
|
|
from modules.morphosyntax.morphosyntax_interface import ( |
|
display_morphosyntax_interface, |
|
display_morphosyntax_results |
|
) |
|
|
|
from modules.semantic.semantic_interface import ( |
|
display_semantic_interface, |
|
display_semantic_results |
|
) |
|
|
|
from modules.discourse.discourse_interface import ( |
|
display_discourse_interface, |
|
display_discourse_results |
|
) |
|
|
|
|
|
|
|
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.semantic_mongo_db import ( |
|
store_student_semantic_result, |
|
get_student_semantic_analysis |
|
) |
|
|
|
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 |
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
@st.cache_resource(show_spinner=False) |
|
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()") |
|
|
|
|
|
if 'initialized' not in st.session_state: |
|
initialize_session_state() |
|
st.session_state.initialized = True |
|
|
|
|
|
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 'morphosyntax_state' not in st.session_state: |
|
st.session_state.morphosyntax_state = { |
|
'last_analysis': None, |
|
'analysis_count': 0 |
|
} |
|
|
|
if 'semantic_state' not in st.session_state: |
|
st.session_state.semantic_state = { |
|
'last_analysis': None, |
|
'analysis_count': 0 |
|
} |
|
|
|
|
|
if 'page' not in st.session_state: |
|
st.session_state.page = 'login' |
|
|
|
|
|
if 'selected_tab' not in st.session_state: |
|
st.session_state.selected_tab = 0 |
|
|
|
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", |
|
key=generate_unique_key("app", "reset_button")): |
|
st.session_state.clear() |
|
st.rerun() |
|
|
|
if __name__ == "__main__": |
|
app_main() |