Update modules/ui/views/landing_view.py
Browse files- modules/ui/views/landing_view.py +127 -81
modules/ui/views/landing_view.py
CHANGED
@@ -1,99 +1,145 @@
|
|
1 |
# modules/ui/views/landing_view.py
|
2 |
import gradio as gr
|
|
|
|
|
3 |
from ...database.sql_db import store_application_request
|
4 |
from datetime import datetime
|
5 |
import uuid
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def create_landing_view():
|
8 |
-
"""Crea la vista de landing con tres columnas"""
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
with gr.Row():
|
13 |
-
# Primera columna - Login (
|
14 |
with gr.Column(scale=1):
|
15 |
-
gr.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
institution = gr.Textbox(
|
35 |
-
label="Institución",
|
36 |
-
placeholder="Universidad, Colegio, Empresa, etc."
|
37 |
-
)
|
38 |
-
role = gr.Dropdown(
|
39 |
-
choices=[
|
40 |
-
"Estudiante",
|
41 |
-
"Profesor",
|
42 |
-
"Investigador",
|
43 |
-
"Otro"
|
44 |
-
],
|
45 |
-
label="Rol",
|
46 |
-
value="Estudiante"
|
47 |
-
)
|
48 |
-
reason = gr.TextArea(
|
49 |
-
label="¿Por qué te interesa usar AIdeaText?",
|
50 |
-
placeholder="Describe brevemente tu interés en la plataforma...",
|
51 |
-
lines=4
|
52 |
-
)
|
53 |
-
|
54 |
-
register_button = gr.Button(
|
55 |
-
"Enviar Solicitud",
|
56 |
-
variant="secondary"
|
57 |
-
)
|
58 |
-
register_message = gr.Markdown()
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
reason=reason
|
77 |
-
)
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
|
94 |
-
#
|
95 |
-
with gr.Column(scale=
|
96 |
-
gr.Markdown("### Videos Tutoriales")
|
97 |
with gr.Tabs():
|
98 |
with gr.TabItem("Introducción"):
|
99 |
gr.Markdown("""
|
|
|
1 |
# modules/ui/views/landing_view.py
|
2 |
import gradio as gr
|
3 |
+
import os
|
4 |
+
from pathlib import Path
|
5 |
from ...database.sql_db import store_application_request
|
6 |
from datetime import datetime
|
7 |
import uuid
|
8 |
|
9 |
+
def get_asset_path(filename, asset_type='img_logo'):
|
10 |
+
"""
|
11 |
+
Obtiene la ruta completa de un asset
|
12 |
+
|
13 |
+
Args:
|
14 |
+
filename (str): Nombre del archivo
|
15 |
+
asset_type (str): Tipo de asset ('img_logo', 'img_social-media', etc.)
|
16 |
+
|
17 |
+
Returns:
|
18 |
+
str: Ruta completa al asset
|
19 |
+
"""
|
20 |
+
current_dir = Path(__file__).parent.parent # sube a /modules/ui
|
21 |
+
asset_path = current_dir / 'assets' / asset_type / filename
|
22 |
+
return str(asset_path)
|
23 |
+
|
24 |
def create_landing_view():
|
25 |
+
"""Crea la vista de landing con tres columnas y header"""
|
26 |
+
# Para el logo
|
27 |
+
logo_path = get_asset_path('logo.png', 'img_logo')
|
28 |
+
# Para iconos de social media.
|
29 |
+
social_icon_path = get_asset_path('twitter.png', 'img_social-media')
|
30 |
+
|
31 |
+
with gr.Blocks(
|
32 |
+
css="""
|
33 |
+
#header-logo {text-align: center; padding: 2rem 0;}
|
34 |
+
#header-logo img {max-width: 200px; height: auto;}
|
35 |
+
.container {max-width: 1200px; margin: 0 auto;}
|
36 |
+
.gr-form {border: 1px solid #e0e0e0; padding: 20px; border-radius: 8px;}
|
37 |
+
"""
|
38 |
+
) as view:
|
39 |
+
# Header con logo
|
40 |
+
with gr.Column(elem_id="header-logo"):
|
41 |
+
gr.Image(
|
42 |
+
value=logo_path,
|
43 |
+
label=None,
|
44 |
+
show_label=False,
|
45 |
+
container=False,
|
46 |
+
height=100
|
47 |
+
)
|
48 |
+
gr.Markdown("# Bienvenido a AIdeaText")
|
49 |
|
50 |
+
with gr.Row(elem_classes="container"):
|
51 |
+
# Primera columna - Tabs de Login y Registro (50%)
|
52 |
with gr.Column(scale=1):
|
53 |
+
with gr.Tabs() as tabs:
|
54 |
+
# Tab de Login
|
55 |
+
with gr.TabItem("Iniciar Sesión", elem_classes="gr-form"):
|
56 |
+
with gr.Column():
|
57 |
+
username = gr.Textbox(
|
58 |
+
label="Usuario",
|
59 |
+
placeholder="Ingrese su usuario"
|
60 |
+
)
|
61 |
+
password = gr.Textbox(
|
62 |
+
label="Contraseña",
|
63 |
+
type="password",
|
64 |
+
placeholder="Ingrese su contraseña"
|
65 |
+
)
|
66 |
+
login_button = gr.Button(
|
67 |
+
"Ingresar",
|
68 |
+
variant="primary",
|
69 |
+
scale=0
|
70 |
+
)
|
71 |
+
login_message = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
# Tab de Registro
|
74 |
+
with gr.TabItem("Solicitud de Acceso", elem_classes="gr-form"):
|
75 |
+
with gr.Column():
|
76 |
+
name = gr.Textbox(
|
77 |
+
label="Nombre Completo",
|
78 |
+
placeholder="Ej: Juan Pérez"
|
79 |
+
)
|
80 |
+
email = gr.Textbox(
|
81 |
+
label="Correo Electrónico",
|
82 |
+
placeholder="[email protected]"
|
83 |
+
)
|
84 |
+
institution = gr.Textbox(
|
85 |
+
label="Institución",
|
86 |
+
placeholder="Universidad, Colegio, Empresa, etc."
|
87 |
+
)
|
88 |
+
role = gr.Dropdown(
|
89 |
+
choices=[
|
90 |
+
"Estudiante",
|
91 |
+
"Profesor",
|
92 |
+
"Investigador",
|
93 |
+
"Otro"
|
94 |
+
],
|
95 |
+
label="Rol",
|
96 |
+
value="Estudiante"
|
97 |
+
)
|
98 |
+
reason = gr.TextArea(
|
99 |
+
label="¿Por qué te interesa usar AIdeaText?",
|
100 |
+
placeholder="Describe brevemente tu interés en la plataforma...",
|
101 |
+
lines=4
|
102 |
+
)
|
103 |
+
register_button = gr.Button(
|
104 |
+
"Enviar Solicitud",
|
105 |
+
variant="secondary",
|
106 |
+
scale=0
|
107 |
+
)
|
108 |
+
register_message = gr.Markdown()
|
109 |
|
110 |
+
def handle_registration(name, email, institution, role, reason):
|
111 |
+
try:
|
112 |
+
if not all([name, email, institution, role, reason]):
|
113 |
+
return gr.Markdown("❌ Todos los campos son obligatorios")
|
114 |
+
|
115 |
+
if "@" not in email or "." not in email:
|
116 |
+
return gr.Markdown("❌ El correo electrónico no es válido")
|
|
|
|
|
117 |
|
118 |
+
success = store_application_request(
|
119 |
+
name=name,
|
120 |
+
email=email,
|
121 |
+
institution=institution,
|
122 |
+
current_role=role,
|
123 |
+
desired_role=role,
|
124 |
+
reason=reason
|
125 |
+
)
|
126 |
|
127 |
+
if success:
|
128 |
+
return gr.Markdown("✅ Solicitud enviada correctamente. Te contactaremos pronto.")
|
129 |
+
else:
|
130 |
+
return gr.Markdown("❌ Error al enviar la solicitud. Por favor, intenta nuevamente.")
|
131 |
|
132 |
+
except Exception as e:
|
133 |
+
return gr.Markdown(f"❌ Error: {str(e)}")
|
134 |
+
|
135 |
+
register_button.click(
|
136 |
+
fn=handle_registration,
|
137 |
+
inputs=[name, email, institution, role, reason],
|
138 |
+
outputs=register_message
|
139 |
+
)
|
140 |
|
141 |
+
# Segunda columna - Videos (50%)
|
142 |
+
with gr.Column(scale=1):
|
|
|
143 |
with gr.Tabs():
|
144 |
with gr.TabItem("Introducción"):
|
145 |
gr.Markdown("""
|