|
|
|
|
|
import streamlit as st |
|
from streamlit_player import st_player |
|
import logging |
|
from datetime import datetime, timezone |
|
from dateutil.parser import parse |
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
from session_state import initialize_session_state, logout |
|
|
|
from translations import get_translations |
|
|
|
from ..auth.auth import authenticate_user, authenticate_student, authenticate_admin |
|
|
|
from ..admin.admin_ui import admin_page |
|
|
|
from ..chatbot import display_sidebar_chat |
|
|
|
|
|
from ..studentact.student_activities_v2 import display_student_activities |
|
from ..studentact.current_situation_interface import display_current_situation_interface |
|
from ..studentact.current_situation_analysis import analyze_text_dimensions |
|
|
|
|
|
|
|
|
|
from ..database.sql_db import ( |
|
store_application_request, |
|
store_student_feedback, |
|
store_application_request |
|
) |
|
|
|
from ..database.mongo_db import ( |
|
get_collection, |
|
insert_document, |
|
find_documents, |
|
update_document, |
|
delete_document |
|
) |
|
|
|
from ..database.morphosintax_mongo_db import ( |
|
store_student_morphosyntax_result, |
|
get_student_morphosyntax_analysis, |
|
update_student_morphosyntax_analysis, |
|
delete_student_morphosyntax_analysis, |
|
get_student_morphosyntax_data |
|
) |
|
|
|
from ..database.chat_mongo_db import store_chat_history, get_chat_history |
|
|
|
|
|
from ..morphosyntax.morphosyntax_interface import ( |
|
display_morphosyntax_interface, |
|
display_morphosyntax_results |
|
) |
|
|
|
from ..semantic.semantic_interface import ( |
|
display_semantic_interface, |
|
display_semantic_results |
|
) |
|
|
|
from ..semantic.semantic_live_interface import display_semantic_live_interface |
|
|
|
from ..discourse.discourse_live_interface import display_discourse_live_interface |
|
|
|
from ..discourse.discourse_interface import ( |
|
display_discourse_interface, |
|
display_discourse_results |
|
) |
|
|
|
def main(): |
|
logger.info(f"Entrando en main() - P谩gina actual: {st.session_state.page}") |
|
|
|
if 'nlp_models' not in st.session_state: |
|
logger.error("Los modelos NLP no est谩n inicializados.") |
|
st.error("Los modelos NLP no est谩n inicializados. Por favor, reinicie la aplicaci贸n.") |
|
return |
|
|
|
lang_code = st.session_state.get('lang_code', 'es') |
|
t = get_translations(lang_code) |
|
|
|
logger.info(f"P谩gina actual antes de la l贸gica de enrutamiento: {st.session_state.page}") |
|
|
|
if st.session_state.get('logged_out', False): |
|
st.session_state.logged_out = False |
|
st.session_state.page = 'login' |
|
st.rerun() |
|
|
|
if not st.session_state.get('logged_in', False): |
|
logger.info("Usuario no ha iniciado sesi贸n. Mostrando p谩gina de login/registro") |
|
login_register_page(lang_code, t) |
|
elif st.session_state.page == 'user': |
|
if st.session_state.role == 'Administrador': |
|
logger.info("Redirigiendo a la p谩gina de administrador") |
|
st.session_state.page = 'Admin' |
|
st.rerun() |
|
else: |
|
logger.info("Renderizando p谩gina de usuario") |
|
user_page(lang_code, t) |
|
elif st.session_state.page == "Admin": |
|
logger.info("Renderizando p谩gina de administrador") |
|
admin_page() |
|
|
|
elif st.session_state.page == "semantic": |
|
|
|
|
|
logger.info("Redirigiendo p谩gina sem谩ntica a p谩gina de usuario") |
|
st.session_state.page = 'user' |
|
st.session_state.selected_tab = 1 |
|
st.rerun() |
|
|
|
elif st.session_state.page == "morpho": |
|
|
|
logger.info("Redirigiendo p谩gina morfosint谩ctica a p谩gina de usuario") |
|
st.session_state.page = 'user' |
|
st.session_state.selected_tab = 0 |
|
st.rerun() |
|
|
|
else: |
|
logger.error(f"P谩gina no reconocida: {st.session_state.page}") |
|
st.error(t.get('unrecognized_page', 'P谩gina no reconocida')) |
|
|
|
st.session_state.page = 'user' |
|
st.rerun() |
|
|
|
logger.info(f"Saliendo de main() - Estado final de la sesi贸n: {st.session_state}") |
|
|
|
def login_register_page(lang_code, t): |
|
|
|
|
|
|
|
left_column, right_column = st.columns([1, 3]) |
|
|
|
with left_column: |
|
tab1, tab2 = st.tabs([t.get("login", "Iniciar Sesi贸n"), |
|
t.get("register", "Registrarse")]) |
|
|
|
with tab1: |
|
login_form(lang_code, t) |
|
|
|
with tab2: |
|
register_form(lang_code, t) |
|
|
|
with right_column: |
|
display_videos_and_info(lang_code, t) |
|
|
|
def login_form(lang_code, t): |
|
with st.form("login_form"): |
|
username = st.text_input(t.get("email", "Correo electr贸nico")) |
|
password = st.text_input(t.get("password", "Contrase帽a"), type="password") |
|
submit_button = st.form_submit_button(t.get("login", "Iniciar Sesi贸n")) |
|
|
|
if submit_button: |
|
success, role = authenticate_user(username, password) |
|
if success: |
|
st.session_state.logged_in = True |
|
st.session_state.username = username |
|
st.session_state.role = role |
|
if role == 'Administrador': |
|
st.session_state.page = 'Admin' |
|
else: |
|
st.session_state.page = 'user' |
|
logger.info(f"Usuario autenticado: {username}, Rol: {role}") |
|
st.rerun() |
|
else: |
|
st.error(t.get("invalid_credentials", "Credenciales incorrectas")) |
|
|
|
def register_form(lang_code, t): |
|
|
|
name = st.text_input(t.get("name", "Nombre")) |
|
lastname = st.text_input(t.get("lastname", "Apellidos")) |
|
institution = st.text_input(t.get("institution", "Instituci贸n")) |
|
current_role = st.selectbox(t.get("current_role", "Rol en la instituci贸n donde labora"), |
|
[t.get("professor", "Profesor"), t.get("student", "Estudiante"), t.get("administrative", "Administrativo")]) |
|
|
|
|
|
desired_role = t.get("student", "Estudiante") |
|
|
|
email = st.text_input(t.get("institutional_email", "Correo electr贸nico de su instituci贸n")) |
|
reason = st.text_area(t.get("interest_reason", "驴Por qu茅 est谩s interesado en probar AIdeaText?")) |
|
|
|
if st.button(t.get("submit_application", "Enviar solicitud")): |
|
logger.info(f"Attempting to submit application for {email}") |
|
logger.debug(f"Form data: name={name}, lastname={lastname}, email={email}, institution={institution}, current_role={current_role}, desired_role={desired_role}, reason={reason}") |
|
|
|
if not name or not lastname or not email or not institution or not reason: |
|
logger.warning("Incomplete form submission") |
|
st.error(t.get("complete_all_fields", "Por favor, completa todos los campos.")) |
|
elif not is_institutional_email(email): |
|
logger.warning(f"Non-institutional email used: {email}") |
|
st.error(t.get("use_institutional_email", "Por favor, utiliza un correo electr贸nico institucional.")) |
|
else: |
|
logger.info(f"Attempting to store application for {email}") |
|
success = store_application_request(name, lastname, email, institution, current_role, desired_role, reason) |
|
if success: |
|
st.success(t.get("application_sent", "Tu solicitud ha sido enviada. Te contactaremos pronto.")) |
|
logger.info(f"Application request stored successfully for {email}") |
|
else: |
|
st.error(t.get("application_error", "Hubo un problema al enviar tu solicitud. Por favor, intenta de nuevo m谩s tarde.")) |
|
logger.error(f"Failed to store application request for {email}") |
|
|
|
def is_institutional_email(email): |
|
forbidden_domains = ['gmail.com', 'hotmail.com', 'yahoo.com', 'outlook.com'] |
|
return not any(domain in email.lower() for domain in forbidden_domains) |
|
|
|
|
|
def display_videos_and_info(lang_code, t): |
|
|
|
tab_gallery, tab_videos, tab_events, tab_news = st.tabs([ |
|
"Fotos de eventos", |
|
"Videos de presentaciones", |
|
"Ponencias acad茅micas", |
|
"Control de versiones" |
|
]) |
|
|
|
|
|
with tab_gallery: |
|
|
|
with st.container(): |
|
|
|
col_left, col_right = st.columns(2) |
|
|
|
|
|
with col_left: |
|
|
|
st.image("assets/img/socialmedia/_MG_2845.JPG", |
|
caption="MakerFaire CDMX 2023", |
|
width=480) |
|
|
|
|
|
|
|
st.image("assets/img/socialmedia/Facebook_CoverPhoto-1_820x312.jpg", |
|
caption="MakerFaire CDMX 2023", |
|
width=480) |
|
|
|
|
|
|
|
with col_right: |
|
st.image("assets/img/socialmedia/_MG_2790.jpg", |
|
caption="MakerFaire CDMX 2024", |
|
width=540) |
|
|
|
|
|
with tab_videos: |
|
videos = { |
|
"Reel AIdeaText": "https://youtu.be/UA-md1VxaRc", |
|
"Presentaci贸n en SENDA, UNAM. Ciudad de M茅xico, M茅xico" : "https://www.youtube.com/watch?v=XFLvjST2cE0", |
|
"Presentaci贸n en PyCon 2024. Colombia, Medell铆n": "https://www.youtube.com/watch?v=Jn545-IKx5Q", |
|
"Presentaci贸n en la Fundaci贸n Ser Maaestro. Lima, Per煤": "https://www.youtube.com/watch?v=imc4TI1q164", |
|
"Presentaci贸n en el programa de incubaci贸n Explora del IFE, TEC de Monterrey, Nuevo Le贸n, M茅xico": "https://www.youtube.com/watch?v=Fqi4Di_Rj_s", |
|
"Entrevista con el Dr. Guillermo Ru铆z. Lima, Per煤": "https://www.youtube.com/watch?v=_ch8cRja3oc", |
|
"Demo de la versi贸n de escritorio.": "https://www.youtube.com/watch?v=nP6eXbog-ZY" |
|
} |
|
|
|
selected_title = st.selectbox("Selecciona una conferencia:", list(videos.keys())) |
|
if selected_title in videos: |
|
try: |
|
st_player(videos[selected_title]) |
|
except Exception as e: |
|
st.error(f"Error al cargar el video: {str(e)}") |
|
|
|
|
|
with tab_events: |
|
st.markdown(""" |
|
## 2025 |
|
|
|
**El Agente Cognitivo Vinculante como Innovaci贸n en el Aprendizaje Adaptativo: el caso de AIdeaText** |
|
IFE CONFERENCE 2025. Organizado por el Instituto para el Futuro de la Educaci贸n del TEC de Monterrey. |
|
Nuevo Le贸n, M茅xico. Del 28 al 30 enero 2025 |
|
|
|
## 2024 |
|
|
|
**AIdeaText, AIdeaText, recurso digital que emplea la t茅cnica de An谩lisis de Resonancia Central para perfeccionar textos acad茅micos** |
|
V Temporada SENDA - Organizado por el Seminario de Entornos y Narrativas Digitales en la Academia del |
|
Instituto de Investigaciones Antropol贸gicas (IIA) de la Universidad Auton贸ma de M茅xico (UNAM). 22 noviembre 2024 |
|
|
|
**Aproximaci贸n al Agente Cognitivo Vinculante (ACV) desde la Teor铆a del Actor Red (TAR)** |
|
Congreso HeETI 2024: Horizontes Expandidos de la Educaci贸n, la Tecnolog铆a y la Innovaci贸n |
|
Universidad el Claustro de Sor Juana. Del 25 al 27 septiembre 2024 |
|
|
|
**AIdeaText, visualizaci贸n de mapas sem谩nticos** |
|
PyCon 2024, Organizado por el grupo de desarrolladores independientes de Python. |
|
Universidad EAFIT, Medell铆n, Colombia. Del 7 al 9 de junio de 2024. |
|
|
|
## 2023 |
|
|
|
**Aproximaci贸n al Agente Cognitivo Vinculante (ACV) desde la Teor铆a del Actor Red (TAR)** |
|
XVII Congreso Nacional de Investigaci贸n Educativa - VII Encuentro de Estudiantes de Posgrado Educaci贸n. |
|
Consejo Mexicano de Investigaci贸n Educativa (COMIE) |
|
Villahermosa, Tabasco, M茅xico. |
|
Del 4 al 8 de diciembre 2023 |
|
|
|
**Aproximaci贸n al Agente Cognitivo Vinculante (ACV) desde la Teor铆a del Actor Red (TAR)** |
|
XXXI Encuentro Internacional de Educaci贸n a Distancia |
|
Universidad de Guadalajara. Jalisco, M茅xico. |
|
Del 27 al 30 noviembre 2023 |
|
|
|
**Aproximaci贸n al Agente Cognitivo Vinculante (ACV) desde la Teor铆a del Actor Red (TAR)** |
|
IV Temporada SENDA - Seminario de Entornos y Narrativas Digitales en la Academia |
|
Instituto de Investigaciones Antropol贸gicas (IIA), UNAM. |
|
22 noviembre 2023 |
|
|
|
**Aproximaci贸n al Agente Cognitivo Vinculante (ACV) desde la Teor铆a del Actor Red (TAR)** |
|
1er Congreso Internacional de Educaci贸n Digital |
|
Instituto Polit茅cnico Nacional, sede Zacatecas. M茅xico. |
|
Del 23 al 24 de noviembre de 2023 |
|
|
|
**La cuesti贸n de la centralidad del maestro frente a las tecnolog铆as digitales generativas** |
|
Innova F贸rum: Ecosistemas de Aprendizaje |
|
Universidad de Guadalajara. Jalisco, M茅xico. |
|
Del 16 al 18 de mayo 2023 |
|
""") |
|
|
|
|
|
with tab_news: |
|
st.markdown(""" |
|
### Novedades de la versi贸n actual |
|
- Interfaz mejorada para una mejor experiencia de usuario |
|
- Optimizaci贸n del an谩lisis morfosint谩ctico |
|
- Soporte para m煤ltiples idiomas |
|
- Nuevo m贸dulo de an谩lisis del discurso |
|
- Sistema de chat integrado para soporte |
|
""") |
|
|
|
|
|
|
|
|
|
def user_page(lang_code, t): |
|
logger.info(f"Entrando en user_page para el estudiante: {st.session_state.username}") |
|
|
|
|
|
if 'selected_tab' not in st.session_state: |
|
st.session_state.selected_tab = 0 |
|
|
|
|
|
if 'semantic_live_active' not in st.session_state: |
|
st.session_state.semantic_live_active = False |
|
|
|
|
|
if 'user_data' not in st.session_state: |
|
with st.spinner(t.get('loading_data', "Cargando tus datos...")): |
|
try: |
|
st.session_state.user_data = get_student_morphosyntax_data(st.session_state.username) |
|
st.session_state.last_data_fetch = datetime.now(timezone.utc).isoformat() |
|
except Exception as e: |
|
logger.error(f"Error al obtener datos del usuario: {str(e)}") |
|
st.error(t.get('data_load_error', "Hubo un problema al cargar tus datos. Por favor, intenta recargar la p谩gina.")) |
|
return |
|
|
|
logger.info(f"Idioma actual: {st.session_state.lang_code}") |
|
logger.info(f"Modelos NLP cargados: {'nlp_models' in st.session_state}") |
|
|
|
|
|
languages = {'Espa帽ol': 'es', 'English': 'en', 'Fran莽ais': 'fr'} |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.stSelectbox > div > div { |
|
padding-top: 0px; |
|
} |
|
.stButton > button { |
|
padding-top: 2px; |
|
margin-top: 0px; |
|
} |
|
div[data-testid="stHorizontalBlock"] > div:nth-child(3) { |
|
display: flex; |
|
justify-content: flex-end; |
|
align-items: center; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
with st.container(): |
|
col1, col2, col3 = st.columns([2, 2, 1]) |
|
with col1: |
|
st.markdown(f"<h3 style='margin-bottom: 0; padding-top: 10px;'>{t['welcome']}, {st.session_state.username}</h3>", |
|
unsafe_allow_html=True) |
|
with col2: |
|
selected_lang = st.selectbox( |
|
t['select_language'], |
|
list(languages.keys()), |
|
index=list(languages.values()).index(st.session_state.lang_code), |
|
key=f"language_selector_{st.session_state.username}_{st.session_state.lang_code}" |
|
) |
|
new_lang_code = languages[selected_lang] |
|
if st.session_state.lang_code != new_lang_code: |
|
st.session_state.lang_code = new_lang_code |
|
st.rerun() |
|
with col3: |
|
if st.button(t['logout'], |
|
key=f"logout_button_{st.session_state.username}_{st.session_state.lang_code}"): |
|
st.session_state.clear() |
|
st.rerun() |
|
|
|
st.markdown("---") |
|
|
|
|
|
chatbot_t = t.get('CHATBOT_TRANSLATIONS', {}).get(lang_code, {}) |
|
|
|
|
|
display_sidebar_chat(lang_code, chatbot_t) |
|
|
|
|
|
if 'tab_states' not in st.session_state: |
|
st.session_state.tab_states = { |
|
'current_situation_active': False, |
|
'morpho_active': False, |
|
'semantic_live_active': False, |
|
'semantic_active': False, |
|
'discourse_live_active': False, |
|
'discourse_active': False, |
|
'activities_active': False, |
|
'feedback_active': False |
|
} |
|
|
|
|
|
tab_names = [ |
|
t.get('current_situation_tab', "Mi Situaci贸n Actual"), |
|
t.get('morpho_tab', 'An谩lisis Morfosint谩ctico'), |
|
t.get('semantic_live_tab', 'An谩lisis Sem谩ntico Vivo'), |
|
t.get('semantic_tab', 'An谩lisis Sem谩ntico'), |
|
t.get('discourse_live_tab', 'An谩lisis de Discurso Vivo'), |
|
t.get('discourse_tab', 'An谩lsis de Discurso'), |
|
t.get('activities_tab', 'Mis Actividades'), |
|
t.get('feedback_tab', 'Formulario de Comentarios') |
|
] |
|
|
|
tabs = st.tabs(tab_names) |
|
|
|
|
|
for index, tab in enumerate(tabs): |
|
with tab: |
|
try: |
|
|
|
if tab.selected and st.session_state.selected_tab != index: |
|
can_switch = True |
|
for state_key in st.session_state.tab_states.keys(): |
|
if st.session_state.tab_states[state_key] and index != get_tab_index(state_key): |
|
can_switch = False |
|
break |
|
if can_switch: |
|
st.session_state.selected_tab = index |
|
|
|
if index == 0: |
|
st.session_state.tab_states['current_situation_active'] = True |
|
display_current_situation_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
elif index == 1: |
|
st.session_state.tab_states['morpho_active'] = True |
|
display_morphosyntax_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
|
|
elif index == 2: |
|
st.session_state.tab_states['semantic_live_active'] = True |
|
display_semantic_live_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
elif index == 3: |
|
st.session_state.tab_states['semantic_active'] = True |
|
display_semantic_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
elif index == 4: |
|
st.session_state.tab_states['discourse_live_active'] = True |
|
display_discourse_live_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
|
|
elif index == 5: |
|
st.session_state.tab_states['discourse_active'] = True |
|
display_discourse_interface( |
|
st.session_state.lang_code, |
|
st.session_state.nlp_models, |
|
t.get('TRANSLATIONS', {}) |
|
) |
|
|
|
elif index == 6: |
|
st.session_state.tab_states['activities_active'] = True |
|
display_student_activities( |
|
username=st.session_state.username, |
|
lang_code=st.session_state.lang_code, |
|
t=t.get('ACTIVITIES_TRANSLATIONS', {}) |
|
) |
|
|
|
elif index == 7: |
|
st.session_state.tab_states['feedback_active'] = True |
|
display_feedback_form( |
|
st.session_state.lang_code, |
|
t |
|
) |
|
|
|
except Exception as e: |
|
|
|
state_key = get_state_key_for_index(index) |
|
if state_key: |
|
st.session_state.tab_states[state_key] = False |
|
logger.error(f"Error en tab {index}: {str(e)}") |
|
st.error(t.get('tab_error', 'Error al cargar esta secci贸n')) |
|
|
|
|
|
def get_tab_index(state_key): |
|
"""Obtiene el 铆ndice del tab basado en la clave de estado""" |
|
index_map = { |
|
'current_situation_active': 0, |
|
'morpho_active': 1, |
|
'semantic_live_active': 2, |
|
'semantic_active': 3, |
|
'discourse_live_active': 4, |
|
'discourse_active': 5, |
|
'activities_active': 6, |
|
'feedback_active': 7 |
|
} |
|
return index_map.get(state_key, -1) |
|
|
|
def get_state_key_for_index(index): |
|
"""Obtiene la clave de estado basada en el 铆ndice del tab""" |
|
state_map = { |
|
0: 'current_situation_active', |
|
1: 'morpho_active', |
|
2: 'semantic_live_active', |
|
3: 'semantic_active', |
|
4: 'discourse_live_active', |
|
5: 'discourse_active', |
|
6: 'activities_active', |
|
7: 'feedback_active' |
|
} |
|
return state_map.get(index) |
|
|
|
|
|
if st.session_state.get('debug_mode', False): |
|
with st.expander("Debug Info"): |
|
st.write(f"P谩gina actual: {st.session_state.page}") |
|
st.write(f"Usuario: {st.session_state.get('username', 'No logueado')}") |
|
st.write(f"Rol: {st.session_state.get('role', 'No definido')}") |
|
st.write(f"Idioma: {st.session_state.lang_code}") |
|
st.write(f"Tab seleccionado: {st.session_state.selected_tab}") |
|
st.write(f"脷ltima actualizaci贸n de datos: {st.session_state.get('last_data_fetch', 'Nunca')}") |
|
|
|
|
|
def display_feedback_form(lang_code, t): |
|
logging.info(f"display_feedback_form called with lang_code: {lang_code}") |
|
|
|
st.header(t['feedback_title']) |
|
|
|
name = st.text_input(t['name']) |
|
email = st.text_input(t['email']) |
|
feedback = st.text_area(t['feedback']) |
|
|
|
if st.button(t['submit']): |
|
if name and email and feedback: |
|
if store_student_feedback(st.session_state.username, name, email, feedback): |
|
st.success(t['feedback_success']) |
|
else: |
|
st.error(t['feedback_error']) |
|
else: |
|
st.warning(t['complete_all_fields']) |
|
|
|
|
|
__all__ = ['main', 'login_register_page', 'initialize_session_state'] |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |