Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,36 @@
|
|
| 1 |
-
#app.py
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
import spaces
|
| 4 |
import torch
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
zero = torch.Tensor([0]).cuda()
|
| 7 |
-
print(zero.device)
|
| 8 |
|
| 9 |
@spaces.GPU
|
| 10 |
def greet(n):
|
| 11 |
-
print(zero.device)
|
| 12 |
return f"Hello {zero + n} Tensor"
|
| 13 |
-
##############################################
|
| 14 |
|
| 15 |
-
|
| 16 |
-
import sys
|
| 17 |
-
import os
|
| 18 |
-
import logging
|
| 19 |
-
from modules.ui.router import create_router
|
| 20 |
-
from modules.database.database_init import initialize_database_connections
|
| 21 |
-
|
| 22 |
-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 23 |
-
|
| 24 |
-
# Configuraci贸n b谩sica
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
| 26 |
logger = logging.getLogger(__name__)
|
| 27 |
|
| 28 |
-
# Verificar variables de entorno
|
| 29 |
-
COSMOS_ENDPOINT = os.getenv("COSMOS_ENDPOINT")
|
| 30 |
-
COSMOS_KEY = os.getenv("COSMOS_KEY")
|
| 31 |
-
if not COSMOS_ENDPOINT or not COSMOS_KEY:
|
| 32 |
-
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY.")
|
| 33 |
-
|
| 34 |
-
# Inicializar la conexi贸n a la base de datos
|
| 35 |
-
if not initialize_database_connections():
|
| 36 |
-
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos.")
|
| 37 |
-
|
| 38 |
-
# Crear la interfaz de login
|
| 39 |
-
# app = create_auth_interface()
|
| 40 |
-
|
| 41 |
-
# Crear la interfaz de usuario y login
|
| 42 |
def initialize_app():
|
| 43 |
"""Inicializa la aplicaci贸n y sus dependencias"""
|
| 44 |
# Verificar variables de entorno
|
| 45 |
-
if not os.getenv("COSMOS_ENDPOINT")
|
| 46 |
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY")
|
| 47 |
|
| 48 |
# Inicializar conexiones a la base de datos
|
|
@@ -56,7 +44,11 @@ def main():
|
|
| 56 |
try:
|
| 57 |
initialize_app()
|
| 58 |
app = create_router()
|
| 59 |
-
app.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
logger.error(f"Error iniciando la aplicaci贸n: {str(e)}")
|
| 62 |
raise
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import logging
|
| 5 |
+
import gradio as gr
|
| 6 |
import spaces
|
| 7 |
import torch
|
| 8 |
|
| 9 |
+
# Configurar el path del proyecto
|
| 10 |
+
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
sys.path.insert(0, PROJECT_ROOT)
|
| 12 |
+
|
| 13 |
+
# Importaciones del proyecto
|
| 14 |
+
from modules.ui.router import create_router
|
| 15 |
+
from modules.database.database_init import initialize_database_connections
|
| 16 |
+
|
| 17 |
+
# Configuraci贸n de CUDA/GPU
|
| 18 |
zero = torch.Tensor([0]).cuda()
|
| 19 |
+
print(zero.device)
|
| 20 |
|
| 21 |
@spaces.GPU
|
| 22 |
def greet(n):
|
| 23 |
+
print(zero.device)
|
| 24 |
return f"Hello {zero + n} Tensor"
|
|
|
|
| 25 |
|
| 26 |
+
# Configuraci贸n de logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
logging.basicConfig(level=logging.INFO)
|
| 28 |
logger = logging.getLogger(__name__)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def initialize_app():
|
| 31 |
"""Inicializa la aplicaci贸n y sus dependencias"""
|
| 32 |
# Verificar variables de entorno
|
| 33 |
+
if not all([os.getenv("COSMOS_ENDPOINT"), os.getenv("COSMOS_KEY")]):
|
| 34 |
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY")
|
| 35 |
|
| 36 |
# Inicializar conexiones a la base de datos
|
|
|
|
| 44 |
try:
|
| 45 |
initialize_app()
|
| 46 |
app = create_router()
|
| 47 |
+
app.launch(
|
| 48 |
+
server_name="0.0.0.0",
|
| 49 |
+
server_port=7860,
|
| 50 |
+
show_error=True # Ayuda a depurar
|
| 51 |
+
)
|
| 52 |
except Exception as e:
|
| 53 |
logger.error(f"Error iniciando la aplicaci贸n: {str(e)}")
|
| 54 |
raise
|