Update app.py
Browse files
app.py
CHANGED
@@ -2,34 +2,9 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import logging
|
4 |
|
5 |
-
from modules.
|
6 |
-
|
7 |
-
authenticate_user,
|
8 |
-
authenticate_student,
|
9 |
-
authenticate_admin,
|
10 |
-
# Manejo de contrase帽as
|
11 |
-
hash_password,
|
12 |
-
verify_password,
|
13 |
-
# Manejo de usuarios
|
14 |
-
register_student,
|
15 |
-
update_student_info,
|
16 |
-
delete_student,
|
17 |
-
# Interfaz de Gradio
|
18 |
-
create_auth_interface,
|
19 |
-
create_user_page
|
20 |
-
)
|
21 |
-
|
22 |
from modules.database.database_init import initialize_database_connections
|
23 |
-
import spaces
|
24 |
-
import torch
|
25 |
-
|
26 |
-
zero = torch.Tensor([0]).cuda()
|
27 |
-
print(zero.device) # <-- 'cpu' 馃
|
28 |
-
|
29 |
-
@spaces.GPU
|
30 |
-
def greet(n):
|
31 |
-
print(zero.device) # <-- 'cuda:0' 馃
|
32 |
-
return f"Hello {zero + n} Tensor"
|
33 |
|
34 |
# Configuraci贸n b谩sica
|
35 |
logging.basicConfig(level=logging.INFO)
|
@@ -45,61 +20,44 @@ if not COSMOS_ENDPOINT or not COSMOS_KEY:
|
|
45 |
if not initialize_database_connections():
|
46 |
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos.")
|
47 |
|
48 |
-
# Crear la interfaz de login
|
49 |
-
# app = create_auth_interface()
|
50 |
-
|
51 |
-
# Crear la interfaz de usuario y login
|
52 |
def main_interface():
|
53 |
"""
|
54 |
-
|
55 |
"""
|
56 |
with gr.Blocks() as app_interface:
|
57 |
-
# Contenedores para
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
# Crear
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
def handle_login_redirect(username=None, role=None):
|
67 |
"""
|
68 |
-
|
69 |
-
Args:
|
70 |
-
username (str): Nombre de usuario.
|
71 |
-
role (str): Rol del usuario.
|
72 |
-
Returns:
|
73 |
-
dict: Actualizaci贸n de visibilidad de los contenedores.
|
74 |
"""
|
75 |
-
if
|
76 |
return {
|
77 |
-
|
78 |
-
|
79 |
}
|
80 |
return {
|
81 |
-
|
82 |
-
|
83 |
}
|
84 |
|
85 |
-
#
|
86 |
-
with
|
87 |
-
|
88 |
-
|
89 |
-
# Contenedor de Usuario
|
90 |
-
with user_container:
|
91 |
-
user_page.render() # Renderiza la p谩gina de usuario
|
92 |
|
93 |
-
#
|
94 |
-
|
95 |
-
|
96 |
-
inputs=[],
|
97 |
-
outputs=[login_container, user_container]
|
98 |
-
)
|
99 |
|
100 |
return app_interface
|
101 |
|
102 |
# Lanzar la aplicaci贸n
|
103 |
if __name__ == "__main__":
|
104 |
app = main_interface()
|
105 |
-
app.launch(server_name="0.0.0.0", server_port=7860, auth=None)
|
|
|
2 |
import os
|
3 |
import logging
|
4 |
|
5 |
+
from modules.ui.landing_ui import create_landing_interface
|
6 |
+
from modules.ui.login_ui import create_login_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
from modules.database.database_init import initialize_database_connections
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Configuraci贸n b谩sica
|
10 |
logging.basicConfig(level=logging.INFO)
|
|
|
20 |
if not initialize_database_connections():
|
21 |
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos.")
|
22 |
|
|
|
|
|
|
|
|
|
23 |
def main_interface():
|
24 |
"""
|
25 |
+
Ruta principal para seleccionar entre Landing Page y Login.
|
26 |
"""
|
27 |
with gr.Blocks() as app_interface:
|
28 |
+
# Contenedores para las interfaces
|
29 |
+
landing_container = gr.Group(visible=True)
|
30 |
+
login_container = gr.Group(visible=False)
|
31 |
|
32 |
+
# Crear interfaces
|
33 |
+
landing_page = create_landing_interface()
|
34 |
+
login_page = create_login_interface()
|
35 |
|
36 |
+
def handle_navigation(page="landing"):
|
|
|
37 |
"""
|
38 |
+
Maneja la navegaci贸n entre Landing Page y Login.
|
|
|
|
|
|
|
|
|
|
|
39 |
"""
|
40 |
+
if page == "login":
|
41 |
return {
|
42 |
+
landing_container: gr.update(visible=False),
|
43 |
+
login_container: gr.update(visible=True),
|
44 |
}
|
45 |
return {
|
46 |
+
landing_container: gr.update(visible=True),
|
47 |
+
login_container: gr.update(visible=False),
|
48 |
}
|
49 |
|
50 |
+
# Landing Page
|
51 |
+
with landing_container:
|
52 |
+
landing_page.render(navigate_to_login=lambda: handle_navigation("login"))
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
# Login Page
|
55 |
+
with login_container:
|
56 |
+
login_page.render(navigate_back=lambda: handle_navigation("landing"))
|
|
|
|
|
|
|
57 |
|
58 |
return app_interface
|
59 |
|
60 |
# Lanzar la aplicaci贸n
|
61 |
if __name__ == "__main__":
|
62 |
app = main_interface()
|
63 |
+
app.launch(server_name="0.0.0.0", server_port=7860, auth=None)
|