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