File size: 3,813 Bytes
8b38f52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
885d581
 
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
import streamlit as st
from modules.database import initialize_mongodb_connection, get_student_data, store_analysis_result
from modules.auth import authenticate_user, get_user_role, register_user
from modules.morpho_analysis import get_repeated_words_colors, highlight_repeated_words, POS_COLORS, POS_TRANSLATIONS
from modules.syntax_analysis import visualize_syntax
from modules.spacy_utils import load_spacy_models
import time

st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")

def main():
    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.")

    if 'logged_in' not in st.session_state:
        st.session_state.logged_in = False

    if not st.session_state.logged_in:
        login_register_page()
    else:
        logged_in_interface()

def login_register_page():
    st.title("AIdeaText")
    
    tab1, tab2 = st.tabs(["Iniciar Sesión", "Registrarse"])
    
    with tab1:
        login_form()
    
    with tab2:
        register_form()

def login_form():
    username = st.text_input("Usuario")
    password = st.text_input("Contraseña", type='password')
    captcha_answer = st.text_input("Captcha: ¿Cuánto es 2 + 3?")
    
    if st.button("Iniciar Sesión"):
        if captcha_answer == "5":
            if authenticate_user(username, password):
                st.success(f"Bienvenido, {username}!")
                st.session_state.logged_in = True
                st.session_state.username = username
                st.session_state.role = get_user_role(username)
                time.sleep(2)
                st.experimental_rerun()
            else:
                st.error("Usuario o contraseña incorrectos")
        else:
            st.error("Captcha incorrecto")

def register_form():
    new_username = st.text_input("Nuevo Usuario")
    new_password = st.text_input("Nueva Contraseña", type='password')
    carrera = st.text_input("Carrera")
    captcha_answer = st.text_input("Captcha: ¿Cuánto es 3 + 4?")
    
    if st.button("Registrarse"):
        if captcha_answer == "7":
            additional_info = {'carrera': carrera}
            if register_user(new_username, new_password, additional_info):
                st.success("Registro exitoso. Por favor, inicia sesión.")
            else:
                st.error("El usuario ya existe o ocurrió un error durante el registro")
        else:
            st.error("Captcha incorrecto")

def logged_in_interface():
    st.sidebar.title(f"Bienvenido, {st.session_state.username}")
    if st.sidebar.button("Cerrar Sesión"):
        st.session_state.logged_in = False
        st.experimental_rerun()

    tab1, tab2, tab3, tab4 = st.tabs(["Análisis morfosintáctico", "Análisis semántico", "Análisis semántico discursivo", "Mi Progreso"])

    with tab1:
        morphosyntactic_analysis()

    with tab2:
        semantic_analysis()

    with tab3:
        discourse_semantic_analysis()

    with tab4:
        if st.session_state.role == "Estudiante":
            display_student_progress(st.session_state.username)
        elif st.session_state.role == "Profesor":
            display_teacher_interface()

def morphosyntactic_analysis():
    st.header("Análisis morfosintáctico")
    # Aquí va el código para el análisis morfosintáctico

def semantic_analysis():
    st.header("Análisis semántico")
    # Aquí va el código para el análisis semántico

def discourse_semantic_analysis():
    st.header("Análisis semántico discursivo")
    # Aquí va el código para el análisis semántico discursivo

def display_student_progress(username):
    # Código existente para mostrar el progreso del estudiante

    if __name__ == "__main__":
        main()