|
|
|
import streamlit as st |
|
from modules.database import initialize_cosmos_sql_connection, initialize_mongodb_connection, create_user, create_admin_user, create_student_user |
|
from modules.auth import authenticate_user, register_user |
|
from modules.admin_ui import admin_page |
|
from modules.ui import ( |
|
main, |
|
login_register_page, |
|
display_morphosyntax_analysis_interface, |
|
display_semantic_analysis_interface, |
|
display_discourse_analysis_interface, |
|
display_student_progress, |
|
display_chatbot_interface |
|
) |
|
from modules.spacy_utils import load_spacy_models |
|
|
|
st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random") |
|
st.cache_data.clear() |
|
st.cache_resource.clear() |
|
|
|
|
|
@st.cache_resource |
|
def load_models(): |
|
return load_spacy_models() |
|
|
|
nlp_models = load_models() |
|
|
|
|
|
def 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 not initialize_mongodb_connection(): |
|
st.warning("La conexión a la base de datos MongoDB 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'} |
|
|
|
|
|
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;'>Bienvenido, {st.session_state.username}</h3>", unsafe_allow_html=True) |
|
with col3: |
|
st.markdown("<p style='font-size: 1.2rem; margin-bottom: 0; padding-top: 15px;'>Selecciona el idioma del texto que analizarás</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") |
|
st.markdown("</div>", unsafe_allow_html=True) |
|
lang_code = languages[selected_lang] |
|
|
|
with col5: |
|
st.markdown("<div style='padding-top: 15px;'>", unsafe_allow_html=True) |
|
if st.button("Cerrar Sesión", 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 = st.tabs(["Análisis morfosintáctico", "Análisis semántico", "Análisis del discurso", "Chat con Llama2", "Mi Progreso"]) |
|
|
|
with tab1: |
|
display_morphosyntax_analysis_interface(nlp_models, lang_code) |
|
with tab2: |
|
display_semantic_analysis_interface(nlp_models, lang_code) |
|
with tab3: |
|
display_discourse_analysis_interface(nlp_models, lang_code) |
|
with tab4: |
|
display_chatbot_interface(lang_code) |
|
with tab5: |
|
display_student_progress(st.session_state.username, lang_code) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |