Update app.py
Browse files
app.py
CHANGED
|
@@ -1,105 +1,62 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
user_page = create_user_page()
|
| 64 |
-
|
| 65 |
-
# Manejo de login exitoso
|
| 66 |
-
def handle_login_redirect(username=None, role=None):
|
| 67 |
-
"""
|
| 68 |
-
Redirige entre la p谩gina de login y la p谩gina de usuario.
|
| 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 username and role:
|
| 76 |
-
return {
|
| 77 |
-
login_container: gr.update(visible=False),
|
| 78 |
-
user_container: gr.update(visible=True)
|
| 79 |
-
}
|
| 80 |
-
return {
|
| 81 |
-
login_container: gr.update(visible=True),
|
| 82 |
-
user_container: gr.update(visible=False)
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
# Contenedor de Login
|
| 86 |
-
with login_container:
|
| 87 |
-
login_page.render() # Renderiza la p谩gina de login
|
| 88 |
-
|
| 89 |
-
# Contenedor de Usuario
|
| 90 |
-
with user_container:
|
| 91 |
-
user_page.render() # Renderiza la p谩gina de usuario
|
| 92 |
-
|
| 93 |
-
# Conectar el manejo del login al evento `load`
|
| 94 |
-
login_page.load(
|
| 95 |
-
fn=handle_login_redirect,
|
| 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)
|
|
|
|
| 1 |
+
#app.py
|
| 2 |
+
#####################################
|
| 3 |
+
import spaces
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
zero = torch.Tensor([0]).cuda()
|
| 7 |
+
print(zero.device) # <-- 'cpu' 馃
|
| 8 |
+
|
| 9 |
+
@spaces.GPU
|
| 10 |
+
def greet(n):
|
| 11 |
+
print(zero.device) # <-- 'cuda:0' 馃
|
| 12 |
+
return f"Hello {zero + n} Tensor"
|
| 13 |
+
##############################################
|
| 14 |
+
|
| 15 |
+
import gradio as gr
|
| 16 |
+
import os
|
| 17 |
+
import logging
|
| 18 |
+
from modules.ui.router import create_router
|
| 19 |
+
from modules.database.database_init import initialize_database_connections
|
| 20 |
+
|
| 21 |
+
# Configuraci贸n b谩sica
|
| 22 |
+
logging.basicConfig(level=logging.INFO)
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
# Verificar variables de entorno
|
| 26 |
+
COSMOS_ENDPOINT = os.getenv("COSMOS_ENDPOINT")
|
| 27 |
+
COSMOS_KEY = os.getenv("COSMOS_KEY")
|
| 28 |
+
if not COSMOS_ENDPOINT or not COSMOS_KEY:
|
| 29 |
+
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY.")
|
| 30 |
+
|
| 31 |
+
# Inicializar la conexi贸n a la base de datos
|
| 32 |
+
if not initialize_database_connections():
|
| 33 |
+
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos.")
|
| 34 |
+
|
| 35 |
+
# Crear la interfaz de login
|
| 36 |
+
# app = create_auth_interface()
|
| 37 |
+
|
| 38 |
+
# Crear la interfaz de usuario y login
|
| 39 |
+
def initialize_app():
|
| 40 |
+
"""Inicializa la aplicaci贸n y sus dependencias"""
|
| 41 |
+
# Verificar variables de entorno
|
| 42 |
+
if not os.getenv("COSMOS_ENDPOINT") or not os.getenv("COSMOS_KEY"):
|
| 43 |
+
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY")
|
| 44 |
+
|
| 45 |
+
# Inicializar conexiones a la base de datos
|
| 46 |
+
if not initialize_database_connections():
|
| 47 |
+
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos")
|
| 48 |
+
|
| 49 |
+
logger.info("Inicializaci贸n completada exitosamente")
|
| 50 |
+
|
| 51 |
+
def main():
|
| 52 |
+
"""Funci贸n principal que inicia la aplicaci贸n"""
|
| 53 |
+
try:
|
| 54 |
+
initialize_app()
|
| 55 |
+
app = create_router()
|
| 56 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|
| 57 |
+
except Exception as e:
|
| 58 |
+
logger.error(f"Error iniciando la aplicaci贸n: {str(e)}")
|
| 59 |
+
raise
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|