Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from modules.database import initialize_mongodb_connection, get_student_data, store_analysis_result
|
| 3 |
+
from modules.auth import authenticate_user, get_user_role, register_user
|
| 4 |
+
from modules.morpho_analysis import get_repeated_words_colors, highlight_repeated_words, POS_COLORS, POS_TRANSLATIONS
|
| 5 |
+
from modules.syntax_analysis import visualize_syntax
|
| 6 |
+
from modules.spacy_utils import load_spacy_models
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
if not initialize_mongodb_connection():
|
| 13 |
+
st.warning("La conexión a la base de datos MongoDB no está disponible. Algunas funciones pueden no estar operativas.")
|
| 14 |
+
|
| 15 |
+
if 'logged_in' not in st.session_state:
|
| 16 |
+
st.session_state.logged_in = False
|
| 17 |
+
|
| 18 |
+
if not st.session_state.logged_in:
|
| 19 |
+
login_register_page()
|
| 20 |
+
else:
|
| 21 |
+
logged_in_interface()
|
| 22 |
+
|
| 23 |
+
def login_register_page():
|
| 24 |
+
st.title("AIdeaText")
|
| 25 |
+
|
| 26 |
+
tab1, tab2 = st.tabs(["Iniciar Sesión", "Registrarse"])
|
| 27 |
+
|
| 28 |
+
with tab1:
|
| 29 |
+
login_form()
|
| 30 |
+
|
| 31 |
+
with tab2:
|
| 32 |
+
register_form()
|
| 33 |
+
|
| 34 |
+
def login_form():
|
| 35 |
+
username = st.text_input("Usuario")
|
| 36 |
+
password = st.text_input("Contraseña", type='password')
|
| 37 |
+
captcha_answer = st.text_input("Captcha: ¿Cuánto es 2 + 3?")
|
| 38 |
+
|
| 39 |
+
if st.button("Iniciar Sesión"):
|
| 40 |
+
if captcha_answer == "5":
|
| 41 |
+
if authenticate_user(username, password):
|
| 42 |
+
st.success(f"Bienvenido, {username}!")
|
| 43 |
+
st.session_state.logged_in = True
|
| 44 |
+
st.session_state.username = username
|
| 45 |
+
st.session_state.role = get_user_role(username)
|
| 46 |
+
time.sleep(2)
|
| 47 |
+
st.experimental_rerun()
|
| 48 |
+
else:
|
| 49 |
+
st.error("Usuario o contraseña incorrectos")
|
| 50 |
+
else:
|
| 51 |
+
st.error("Captcha incorrecto")
|
| 52 |
+
|
| 53 |
+
def register_form():
|
| 54 |
+
new_username = st.text_input("Nuevo Usuario")
|
| 55 |
+
new_password = st.text_input("Nueva Contraseña", type='password')
|
| 56 |
+
carrera = st.text_input("Carrera")
|
| 57 |
+
captcha_answer = st.text_input("Captcha: ¿Cuánto es 3 + 4?")
|
| 58 |
+
|
| 59 |
+
if st.button("Registrarse"):
|
| 60 |
+
if captcha_answer == "7":
|
| 61 |
+
additional_info = {'carrera': carrera}
|
| 62 |
+
if register_user(new_username, new_password, additional_info):
|
| 63 |
+
st.success("Registro exitoso. Por favor, inicia sesión.")
|
| 64 |
+
else:
|
| 65 |
+
st.error("El usuario ya existe o ocurrió un error durante el registro")
|
| 66 |
+
else:
|
| 67 |
+
st.error("Captcha incorrecto")
|
| 68 |
+
|
| 69 |
+
def logged_in_interface():
|
| 70 |
+
st.sidebar.title(f"Bienvenido, {st.session_state.username}")
|
| 71 |
+
if st.sidebar.button("Cerrar Sesión"):
|
| 72 |
+
st.session_state.logged_in = False
|
| 73 |
+
st.experimental_rerun()
|
| 74 |
+
|
| 75 |
+
tab1, tab2, tab3, tab4 = st.tabs(["Análisis morfosintáctico", "Análisis semántico", "Análisis semántico discursivo", "Mi Progreso"])
|
| 76 |
+
|
| 77 |
+
with tab1:
|
| 78 |
+
morphosyntactic_analysis()
|
| 79 |
+
|
| 80 |
+
with tab2:
|
| 81 |
+
semantic_analysis()
|
| 82 |
+
|
| 83 |
+
with tab3:
|
| 84 |
+
discourse_semantic_analysis()
|
| 85 |
+
|
| 86 |
+
with tab4:
|
| 87 |
+
if st.session_state.role == "Estudiante":
|
| 88 |
+
display_student_progress(st.session_state.username)
|
| 89 |
+
elif st.session_state.role == "Profesor":
|
| 90 |
+
display_teacher_interface()
|
| 91 |
+
|
| 92 |
+
def morphosyntactic_analysis():
|
| 93 |
+
st.header("Análisis morfosintáctico")
|
| 94 |
+
# Aquí va el código para el análisis morfosintáctico
|
| 95 |
+
|
| 96 |
+
def semantic_analysis():
|
| 97 |
+
st.header("Análisis semántico")
|
| 98 |
+
# Aquí va el código para el análisis semántico
|
| 99 |
+
|
| 100 |
+
def discourse_semantic_analysis():
|
| 101 |
+
st.header("Análisis semántico discursivo")
|
| 102 |
+
# Aquí va el código para el análisis semántico discursivo
|
| 103 |
+
|
| 104 |
+
def display_student_progress(username):
|
| 105 |
+
# Código existente para mostrar el progreso del estudiante
|
| 106 |
+
|
| 107 |
+
def display_teacher_interface():
|
| 108 |
+
st.write("Bienvenido, profesor. Aquí podrás ver el progreso de tus estudiantes.")
|
| 109 |
+
# Aquí puedes agregar la lógica para mostrar el progreso de los estudiantes
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
main()
|