# modules/ui/ui.py
import streamlit as st
from PIL import Image
import base64
from streamlit_player import st_player
import logging
from datetime import datetime
from dateutil.parser import parse
#########################################################
# Configuración de estilo CSS para el carrusel
st.markdown("""
""", unsafe_allow_html=True)
# Datos del carrusel (imágenes y descripciones)
eventos = [
{
"imagen": "assets/img/socialmedia/WebSummit_ShowCase_2025.png",
"titulo": "WebSummitRio 2025, Rio, Brazil, April 27-30",
"descripcion": "AIdeaText showcase"
},
{
"imagen": "assets/img/socialmedia/image_pycon_2024.png",
"titulo": "PyCon 2024, Medellin, Colombia, June 7-9",
"descripcion": "AIdeaText showcase"
},
{
"imagen": "assets/img/socialmedia/_MG_2845.JPG",
"titulo": "MakerFaire 2024, Mexico City, Mexico, October 12-13",
"descripcion": "AIdeaText showcase"
}
]
#####################
def initialize_carousel_state():
"""Inicializa todas las variables de estado necesarias para el carrusel"""
if not hasattr(st.session_state, 'current_event'):
st.session_state.current_event = 0
if not hasattr(st.session_state, 'carousel_initialized'):
st.session_state.carousel_initialized = True
#####################
def show_carousel():
"""Muestra el carrusel de imágenes con inicialización segura del estado"""
try:
# Inicialización segura del estado
initialize_carousel_state()
# Verificación adicional
if not hasattr(st.session_state, 'current_event'):
st.session_state.current_event = 0
st.rerun()
current_idx = st.session_state.current_event
with st.container():
#st.markdown("
Eventos Relevantes
",
# unsafe_allow_html=True)
# Controles de navegación
col1, col2, col3 = st.columns([1, 6, 1])
with col1:
if st.button("◀", key="carousel_prev"):
st.session_state.current_event = (current_idx - 1) % len(eventos)
st.rerun()
with col2:
event = eventos[current_idx]
img = Image.open(event["imagen"]) if isinstance(event["imagen"], str) else event["imagen"]
st.image(
img,
use_container_width=True,
caption=f"{event['titulo']} - {event['descripcion']}"
)
with col3:
if st.button("▶", key="carousel_next"):
st.session_state.current_event = (current_idx + 1) % len(eventos)
st.rerun()
# Indicadores de posición (solo visuales, no botones)
st.markdown("", unsafe_allow_html=True)
for i in range(len(eventos)):
active_class = "carousel-dot active" if i == current_idx else "carousel-dot"
st.markdown(f"", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
except Exception as e:
st.error(f"Error al mostrar el carrusel: {str(e)}")
logger.error(f"Error en show_carousel: {str(e)}")
#########################################################
# Configura el logger PRIMERO, antes de cualquier uso
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
#########################################################
# Importaciones locales
from session_state import initialize_session_state, logout
from translations import get_translations, get_landing_translations
from ..auth.auth import authenticate_user, authenticate_student, authenticate_admin
from ..database.sql_db import store_application_request
from ..admin.admin_ui import admin_page
#########################################################
# Intento de importación con logger YA DEFINIDO
try:
from .user_page import user_page
except ImportError as e:
logger.error(f"No se pudo importar user_page: {str(e)}. Asegúrate de que el archivo existe.")
# Función de respaldo
def user_page(lang_code, t):
st.error("La página de usuario no está disponible. Por favor, contacta al administrador.")
#############################################################
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
# [1] CONFIGURAR INGLÉS COMO IDIOMA POR DEFECTO
if 'lang_code' not in st.session_state:
st.session_state.lang_code = 'en' # Inglés por defecto
lang_code = st.session_state.get('lang_code', 'en')
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()
else:
logger.error(f"Página no reconocida: {st.session_state.page}")
st.error(t.get('unrecognized_page', 'Página no reconocida'))
# Redirigir a la página de usuario en caso de error
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):
# Obtener traducciones específicas para landing page
landing_t = get_landing_translations(lang_code)
# Language selection dropdown at the top
languages = {
'English': 'en',
'Español': 'es',
'Français': 'fr',
'Português': 'pt'
}
# Estilo personalizado para mejorar el espaciado y alineación
st.markdown("""
""", unsafe_allow_html=True)
####################################################################################################################################
# Pie de página legal (debe ir al final de la función)
footer_placeholder = st.empty()
footer_placeholder.markdown("""
""", unsafe_allow_html=True)
#################################### LOGOS ################################################################################################
# ============================================
# [1] LOGO AIdeaText CENTRADO - UNA SOLA FILA
# ============================================
# Opción 1: Usar columnas para centrar
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("---")
#######################################################################
# Main content with columns
left_column, right_column = st.columns([1, 3])
with left_column:
# ============================================
# [2] CONTENEDOR "COMIENZA" CON SELECTOR DE IDIOMA
# ============================================
st.markdown("""
🚀 Start in
""", unsafe_allow_html=True)
# Selector de idioma inline
selected_lang = st.selectbox(
"",
list(languages.keys()),
index=list(languages.keys()).index('English'), # Inglés seleccionado por defecto
label_visibility="collapsed",
key="landing_language_selector"
)
st.markdown("""
""", unsafe_allow_html=True)
new_lang_code = languages[selected_lang]
if lang_code != new_lang_code:
st.session_state.lang_code = new_lang_code
st.rerun()
# Crear tabs - REGISTRO siempre primero
tab_titles = [f"📝 {landing_t['register']}", f"🔐 {landing_t['login']}"]
tabs = st.tabs(tab_titles)
# TAB 1: FORMULARIO DE REGISTRO (Siempre visible por defecto)
with tabs[0]:
register_form(lang_code, landing_t)
# TAB 2: FORMULARIO DE LOGIN
with tabs[1]:
login_form(lang_code, landing_t)
with right_column:
display_videos_and_info(lang_code, landing_t)
#############################################################
#############################################################
def login_form(lang_code, landing_t):
with st.form("login_form"):
username = st.text_input(landing_t['email'])
password = st.text_input(landing_t['password'], type="password")
submit_button = st.form_submit_button(landing_t['login_button'])
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(landing_t['invalid_credentials'])
#############################################################
def register_form(lang_code, landing_t):
"""Formulario de registro simplificado - SOLO 3 CAMPOS"""
# Verificar si acabamos de registrar exitosamente
if 'just_registered' in st.session_state and st.session_state.just_registered:
st.success("✅ Registration successful! Your request has been sent.")
st.info("Please check your email for further instructions.")
# Botón para limpiar y empezar de nuevo
if st.button("Register another user"):
del st.session_state.just_registered
st.rerun()
return
# Solo 3 campos requeridos
name = st.text_input("Full name *", key="reg_name")
email = st.text_input("Institutional email *", key="reg_email")
institution = st.text_input("Educational institution *", key="reg_institution")
# Botón simplificado
if st.button(landing_t['submit_application'], type="primary"):
logger.info(f"Trying to send request for {email}")
# Validaciones básicas
if not name or not email or not institution:
st.error("Please complete all required fields (*)")
return
if not is_institutional_email(email):
st.error("Please use an institutional email (not gmail, hotmail, etc.)")
return
# Enviar solicitud
success = store_application_request(
name=name,
lastname="",
email=email,
institution=institution,
current_role="Student",
desired_role="Student",
reason="New registration"
)
if success:
# Marcar que acabamos de registrar
st.session_state.just_registered = True
logger.info(f"Request successfully stored for {email}")
# Mostrar mensaje y recargar
st.success("✅ Your request has been sent! You will receive an email with instructions.")
st.balloons()
# Recargar después de 2 segundos
import time
time.sleep(2)
st.rerun()
else:
st.error("❌ There was an error sending your request. Please try again.")
logger.error(f"Error storing 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, landing_t):
# ============================================
# NUEVO ORDEN DE TABS CON 6 OPCIONES
# ============================================
tab_about, tab_programs, tab_competitions, tab_use_case, tab_presentations, tab_gallery = st.tabs([
"👥 About Us",
"🏆 Current Programs",
"💰 Competitions",
"🎯 Use Cases",
"🎬 Pitches & Presentations",
"📸 Events & Recognition"
])
# ============================================
# ESTILOS GLOBALES PARA CONSISTENCIA
# ============================================
st.markdown("""
""", unsafe_allow_html=True)
# ============================================
# TAB 1: 👥 ABOUT US - SIMPLIFICADO CON DESPLEGABLES
# ============================================
with tab_about:
# NO repetir "About Us" - el tab ya lo dice
about_texts = {
'en': """
AIdeaText has this fundamental principle:
"The real transformation happens when we stop grading what students produce and start assessing how they think."
Our Mission & Vision
🎯 Mission: To transform how the world measures and develops critical thinking.
🌍 Vision: To be the global standard for cognitive development assessment.
We bridge the gap between educational training and business needs by implementing
cognitive development measurement systems based on advanced natural language processing.
Who We Are
AIdeaText is a digital technology company for human cognitive development based in Mexico.
Our solution has its core business in Semantic Reasoning Graphs (SRGs), a technological
configuration that makes the critical thinking process visible, connecting educational
training with business needs by implementing a cognitive development measurement system
based on advanced natural language processing.
Validation & Stage
We have been validated by the NVIDIA Inception program for emerging companies and are in
an advanced development stage with:
•
Functional MVP Demo
•
Scalable business model in Latin America
Key Differentiators
• First cognitive development measurement system based on NLP
• Semantic Reasoning Graphs make thinking visible
• Validated by NVIDIA Inception Program
• Scalable model for Latin American education market
• Proven technology with functional MVP
• Connects education with business needs
"""
}
# Agregar estilos para los desplegables de About Us
st.markdown("""
""", unsafe_allow_html=True)
about_content = about_texts.get(lang_code, about_texts['en'])
st.markdown(about_content, unsafe_allow_html=True)
# ============================================
# TAB 2: 🏆 CURRENT PROGRAMS
# ============================================
with tab_programs:
# NO repetir "Current Programs" - el tab ya lo dice
st.markdown('NVIDIA Inception Program
', unsafe_allow_html=True)
# Fila 1: NVIDIA Inception
col_nvidia_logo, col_nvidia_text = st.columns([1, 3])
with col_nvidia_logo:
st.image("https://huggingface.co/spaces/AIdeaText/v5Prod/resolve/main/assets/img/socialmedia/nvidia/nvidia-inception-program-badge-rgb-for-screen.png",
width=300)
with col_nvidia_text:
st.markdown("""
Exclusive program for AI and Deep Tech startups
Inception is a free program that guides AI startups through the NVIDIA platform and ecosystem.
From prototype to production, Inception meets you where you are, with member benefits to help
you discover new AI opportunities, build with world-class technologies, and grow your business.
More info: [https://www.nvidia.com/en-us/startups/]
Status: Active Member
""", unsafe_allow_html=True)
st.markdown("---")
st.markdown('incMTY Accelerator
', unsafe_allow_html=True)
# Fila 2: incMTY
col_inc_logo, col_inc_text = st.columns([1, 3])
with col_inc_logo:
st.image("https://huggingface.co/spaces/AIdeaText/v5Dev/resolve/main/assets/img/Logo_incMTY.png",
width=250)
with col_inc_text:
st.markdown("""
Deep Tech acceleration program
PotencIA MX Accelerator will boost 30 organizations through a virtual acceleration program.
After two high-impact bootcamps in Monterrey and Mexico City, the selected startups and SMEs will begin
a six-month acceleration program. During this time, they will develop solutions with Open Source LLMs like Llama de Meta
and receive mentorship, specialized services, and strategy and growth workshops. The program will culminate in Demo Day 2026,
where the most outstanding organizations will be recognized: one startup will receive a business development trip with ecosystem partners,
and one SME will be offered soft landing support in new markets.
Status: Current member
""", unsafe_allow_html=True)
# ============================================
# TAB 3: 💰 COMPETITIONS
# ============================================
with tab_competitions:
# NO repetir "Competitions" - el tab ya lo dice
competitions_text = {
'en': """
Competing for $950K USD in prizes across multiple prestigious competitions.
NVIDIA Inception Demo Pitch – GTC 2026 - March 16–19 in San Jose, California
This is a unique opportunity for startups leveraging NVIDIA technologies in innovative ways to showcase their work.
By completing the form below, you'll be considered to present a live, 5-minute demo or pitch at GTC,
highlighting your startup's progress and how NVIDIA technology is accelerating your success.
More info: https://www.nvidia.com/gtc/?ncid=GTC-NV7HIY70L
Kaggle/Google Tunix Hackathon - Explainable AI Models
Most open-source or open-weight language models can give you an answer. But they typically don't 'show their work'
- the steps they went through to arrive at that conclusion in a consistent manner. Here, you'll use Tunix,
Google's new JAX-native library for LLM post-training, to train a model to show its work by laying out a
reasoning trace before landing on an answer.
More info: https://kaggle.com/competitions/google-tunix-hackathon
Tools Competition – Dataset Track - Datasets for Education Innovation
The 2026 Tools Competition launches at a time of rapid change, rising urgency,
and widespread demand for understanding and direction amidst evolving technology.
Learners of all ages face new demands driven by AI,
shifting labor markets, and persistent inequities. From early learning to workforce development,
they need tools that are more effective, inclusive, and future-ready.
More info: https://tools-competition.org/26-overview/
"""
}
# Si necesitas agregar estilos CSS para los detalles
st.markdown("""
""", unsafe_allow_html=True)
content = competitions_text.get(lang_code, competitions_text['en'])
st.markdown(content, unsafe_allow_html=True)
#st.markdown("---")
#if st.button("🎯 Apply as Beta Tester", use_container_width=True):
# st.info("Beta tester program launching Q1 2025")
# ============================================
# TAB 4: 🎯 USE CASES
# ============================================
with tab_use_case:
# NO repetir "Use Cases" - el tab ya lo dice
st.markdown("""
Select a demonstration to see practical applications of our technology:
""", unsafe_allow_html=True)
use_case_videos = {
"📊 Semantic Analysis Example in portuguese ": "https://youtu.be/_4WMufl6MTA",
"💻 First Demo - Standalone version ": "https://www.youtube.com/watch?v=nP6eXbog-ZY"
}
selected_title = st.selectbox(
"Select demonstration:",
list(use_case_videos.keys())
)
if selected_title in use_case_videos:
try:
st_player(
use_case_videos[selected_title],
height=400,
playing=False,
controls=True,
light=True
)
except Exception as e:
st.error(f"Error loading video: {str(e)}")
# Información adicional sobre casos de uso
st.markdown("""
Applications
For Students:
• Visualize thinking processes
• Receive immediate feedback
• Improve academic writing
• Track cognitive progress
For Educators:
• Assess deep understanding
• Identify individual needs
• Personalize teaching
• Save grading time
For Institutions:
• Measure cognitive development
• Improve academic outcomes
• Validated educational innovation
• Data for research
""", unsafe_allow_html=True)
# ============================================
# TAB 5: 🎬 PITCHES & PRESENTATIONS
# ============================================
with tab_presentations:
# NO repetir "Pitches & Presentations" - el tab ya lo dice
st.markdown("""
Watch our key pitches, demonstrations, and conference presentations:
""", unsafe_allow_html=True)
videos = {
"🎬 Pitch - PotencIA MX": "https://youtu.be/Nt7IEas_P54",
"🏆 Conference - SENDA UNAM": "https://www.youtube.com/watch?v=XFLvjST2cE0",
"🐍 Conference - PyCon 2024": "https://www.youtube.com/watch?v=Jn545-IKx5Q",
"👨🏫 Conference - Ser Maestro Foundation": "https://www.youtube.com/watch?v=imc4TI1q164",
"🚀 Pitch - Explora - IFE - TEC de Monterrey": "https://www.youtube.com/watch?v=Fqi4Di_Rj_s",
"🎙️ Interview with Dr. Guillermo Ruíz": "https://www.youtube.com/watch?v=_ch8cRja3oc"
}
selected_title = st.selectbox(
"Select video:",
list(videos.keys())
)
if selected_title in videos:
try:
st_player(
videos[selected_title],
height=400,
playing=False,
controls=True,
light=True
)
except Exception as e:
st.error(f"Error loading video: {str(e)}")
# Próximos eventos
st.markdown("""
Upcoming Events
Confirmed next events for 2026
•
Stay in touch
Confirmed participation in showcases and panels.
""", unsafe_allow_html=True)
# ============================================
# TAB 6: 📸 EVENTS & RECOGNITION
# ============================================
with tab_gallery:
# NO repetir "Events & Recognition" - el tab ya lo dice
st.markdown("""
Gallery of our participation in events and recognition received:
""", unsafe_allow_html=True)
show_carousel()
#############################################################
#############################################################
# Definición de __all__ para especificar qué se exporta
__all__ = ['main', 'login_register_page', 'initialize_session_state']
# Bloque de ejecución condicional
if __name__ == "__main__":
main()