|
print("Iniciando app.py") |
|
|
|
|
|
import streamlit as st |
|
print("Importaciones completadas") |
|
|
|
from modules.database.database import ( |
|
initialize_database_connections, |
|
initialize_cosmos_sql_connection, |
|
initialize_mongodb_connection, |
|
create_user, |
|
create_admin_user, |
|
create_student_user |
|
) |
|
|
|
from modules.auth.auth import authenticate_user, register_user |
|
|
|
from modules.admin.admin_ui import admin_page |
|
|
|
from modules.ui.ui import ( |
|
login_register_page, |
|
login_form, |
|
display_morphosyntax_analysis_interface, |
|
display_semantic_analysis_interface, |
|
display_discourse_analysis_interface, |
|
display_student_progress, |
|
display_chatbot_interface, |
|
display_feedback_form |
|
) |
|
from modules.utils.spacy_utils import load_spacy_models |
|
import logging |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
print("Configurando página") |
|
st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random") |
|
st.cache_data.clear() |
|
st.cache_resource.clear() |
|
|
|
|
|
print("Cargando modelos") |
|
@st.cache_resource |
|
def load_models(): |
|
return load_spacy_models() |
|
|
|
nlp_models = load_models() |
|
print("Modelos cargados") |
|
|
|
|
|
def main(): |
|
print("Entrando en main()") |
|
|
|
if 'initialized' not in st.session_state: |
|
st.session_state.clear() |
|
st.session_state.initialized = True |
|
st.session_state.logged_in = False |
|
st.session_state.page = 'login' |
|
st.session_state.username = None |
|
st.session_state.role = None |
|
|
|
|
|
if 'db_initialized' not in st.session_state: |
|
st.session_state.db_initialized = initialize_database_connections() |
|
|
|
|
|
if not st.session_state.db_initialized.get("mongodb", False): |
|
st.warning("La conexión a la base de datos MongoDB no está disponible. Algunas funciones pueden no estar operativas.") |
|
if not st.session_state.db_initialized.get("cosmos_sql", False): |
|
st.warning("La conexión a Cosmos DB SQL API no está disponible. Algunas funciones pueden no estar operativas.") |
|
|
|
print(f"Página actual: {st.session_state.page}") |
|
print(f"Rol del usuario: {st.session_state.role}") |
|
|
|
|
|
if st.session_state.page == 'login': |
|
login_register_page() |
|
elif st.session_state.page == 'admin': |
|
print("Intentando mostrar página de admin") |
|
admin_page() |
|
elif st.session_state.page == 'user': |
|
logged_in_interface() |
|
else: |
|
print(f"Página no reconocida: {st.session_state.page}") |
|
|
|
print(f"Estado final de la sesión: {st.session_state}") |
|
|
|
|
|
def logged_in_interface(): |
|
languages = {'Español': 'es', 'English': 'en', 'Français': 'fr'} |
|
|
|
translations = { |
|
'es': { |
|
'welcome': "Bienvenido", |
|
'select_language': "Selecciona el idioma del texto que analizarás", |
|
'logout': "Cerrar Sesión", |
|
'tabs': ["Análisis morfosintáctico", "Análisis semántico", "Análisis del discurso", "Chat con Llama2", "Mi Progreso", "Formulario de Retroalimentación"] |
|
}, |
|
'en': { |
|
'welcome': "Welcome", |
|
'select_language': "Select the language of the text you will analyze", |
|
'logout': "Log Out", |
|
'tabs': ["Morphosyntactic Analysis", "Semantic Analysis", "Discourse Analysis", "Chat with Llama2", "My Progress", "Feedback Form"] |
|
}, |
|
'fr': { |
|
'welcome': "Bienvenue", |
|
'select_language': "Sélectionnez la langue du texte que vous allez analyser", |
|
'logout': "Déconnexion", |
|
'tabs': ["Analyse morphosyntaxique", "Analyse sémantique", "Analyse du discours", "Chat avec Llama2", "Mon Progrès", "Formulaire de Rétroaction"] |
|
} |
|
} |
|
|
|
|
|
if 'current_lang' not in st.session_state: |
|
st.session_state.current_lang = 'es' |
|
|
|
|
|
with st.container(): |
|
|
|
col1, col2, col3, col4, col5 = st.columns([1, 1, 0.8, 1, 1]) |
|
with col1: |
|
st.markdown(f"<h3 style='margin-bottom: 0;'>{translations[st.session_state.current_lang]['welcome']}, {st.session_state.username}</h3>", unsafe_allow_html=True) |
|
with col3: |
|
st.markdown(f"<p style='font-size: 1.2rem; margin-bottom: 0; padding-top: 15px;'>{translations[st.session_state.current_lang]['select_language']}</p>", unsafe_allow_html=True) |
|
with col4: |
|
st.markdown("<div style='padding-top: 15px;'>", unsafe_allow_html=True) |
|
selected_lang = st.selectbox("", list(languages.keys()), key="language_selector", label_visibility="collapsed", index=list(languages.values()).index(st.session_state.current_lang)) |
|
st.markdown("</div>", unsafe_allow_html=True) |
|
lang_code = languages[selected_lang] |
|
if st.session_state.current_lang != lang_code: |
|
st.session_state.current_lang = lang_code |
|
st.experimental_rerun() |
|
|
|
with col5: |
|
st.markdown("<div style='padding-top: 15px;'>", unsafe_allow_html=True) |
|
if st.button(translations[st.session_state.current_lang]['logout'], key="logout_button"): |
|
st.session_state.logged_in = False |
|
st.experimental_rerun() |
|
st.markdown("</div>", unsafe_allow_html=True) |
|
|
|
|
|
st.markdown("---") |
|
|
|
|
|
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(translations[st.session_state.current_lang]['tabs']) |
|
|
|
with tab1: |
|
display_morphosyntax_analysis_interface(nlp_models, st.session_state.current_lang) |
|
with tab2: |
|
display_semantic_analysis_interface(nlp_models, st.session_state.current_lang) |
|
with tab3: |
|
display_discourse_analysis_interface(nlp_models, st.session_state.current_lang) |
|
with tab4: |
|
display_chatbot_interface(st.session_state.current_lang) |
|
with tab5: |
|
display_student_progress(st.session_state.username, st.session_state.current_lang) |
|
with tab6: |
|
display_feedback_form(st.session_state.current_lang) |
|
|
|
|
|
if __name__ == "__main__": |
|
print("Llamando a main()") |
|
main() |