|
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") |
|
|
|
|
|
def semantic_analysis(): |
|
st.header("Análisis semántico") |
|
|
|
|
|
def discourse_semantic_analysis(): |
|
st.header("Análisis semántico discursivo") |
|
|
|
|
|
def display_student_progress(username): |
|
|
|
|
|
def display_teacher_interface(): |
|
st.write("Bienvenido, profesor. Aquí podrás ver el progreso de tus estudiantes.") |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |