File size: 5,474 Bytes
0217266 6e5dd3f 70dadb7 6e5dd3f 84bb5c9 6e5dd3f 84bb5c9 fb37db5 7fd9803 fb37db5 4ef2a8a fb37db5 976447a 6e5dd3f eca09d8 f4e5e52 eca09d8 f4e5e52 768d6a6 f4e5e52 5fb58ce eca09d8 f4e5e52 eca09d8 f4e5e52 d7a2be2 f4e5e52 b5fc123 d12d2d2 eca09d8 6e5dd3f 0217266 6e5dd3f c7b4af7 6e5dd3f c7b4af7 6e5dd3f a805ad1 447b6a2 c7b4af7 447b6a2 c7b4af7 447b6a2 6e5dd3f c7b4af7 142666d cd645bd 7fc5c4d aea69d3 6e5dd3f 16bf0f4 6e5dd3f 0217266 6e5dd3f c7b4af7 16bf0f4 c7b4af7 16bf0f4 6e5dd3f 0217266 6e5dd3f c7b4af7 6e5dd3f c58df45 |
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 |
# AIdeaText v3
# app.py
import logging
import streamlit as st
import sys
import os
from dotenv import load_dotenv
from datetime import datetime
from PIL import Image
# Configuraci贸n b谩sica
load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Configuraci贸n b谩sica de la p谩gina
st.set_page_config(
page_title="AIdeaText",
layout="wide",
initial_sidebar_state="collapsed" # Para dar m谩s espacio al logo
)
######################
# Primero, definir el CSS personalizado para el logo
st.html("""
<style>
[alt=Logo] {
height: 6rem;
max-width: 100%;
object-fit: contain;
margin: -9rem 0;
}
[data-testid="stSidebar"] [alt=Logo] {
filter: none !important;
}
</style>
""")
# Ahora el logo
st.logo(
"./assets/img/logo_92x92.png",
size="large", # Esto se sobrescribir谩 con el CSS
link="https://aideatext-v3.hf.space"
)
######################
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Importaciones locales
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
# Importaciones de interfaces
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
)
# Importaciones de base de datos
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.database.chat_mongo_db import (
store_chat_history,
get_chat_history
)
# Importaciones de base de datos
from modules.studentact.student_activities_v2 import display_student_activities
from modules.studentact.current_situation_interface import display_current_situation_interface
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()")
# Inicializar el estado de la sesi贸n
if 'initialized' not in st.session_state:
initialize_session_state()
st.session_state.initialized = True
# Inicializar conexiones a bases de datos si no se ha hecho
if 'db_initialized' not in st.session_state:
st.session_state.db_initialized = initialize_database_connections()
# Cargar modelos NLP si no se ha hecho
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")
# Inicializar estados de an谩lisis si no existen
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
}
# Configurar la p谩gina inicial si no est谩 configurada
if 'page' not in st.session_state:
st.session_state.page = 'login'
# Prevenir reinicios innecesarios preservando el estado
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}")
# Dirigir el flujo a la interfaz de usuario principal
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() |