File size: 1,575 Bytes
fd7ed81 a472322 fd7ed81 d00444a a472322 fd7ed81 d00444a fd7ed81 d00444a fd7ed81 d00444a fd7ed81 d00444a fd7ed81 d00444a fd7ed81 d00444a |
1 2 3 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 |
# app.py
# app.py
import os
import sys
import logging
import gradio as gr
import spaces
import torch
# Asegurarnos que el directorio ra铆z est谩 en el path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Importaciones del proyecto
from modules.ui.router import create_router
from modules.database.database_init import initialize_database_connections
# Configuraci贸n de CUDA/GPU
zero = torch.Tensor([0]).cuda()
print(zero.device)
@spaces.GPU
def greet(n):
print(zero.device)
return f"Hello {zero + n} Tensor"
# Configuraci贸n de logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def initialize_app():
"""Inicializa la aplicaci贸n y sus dependencias"""
# Verificar variables de entorno
if not all([os.getenv("COSMOS_ENDPOINT"), os.getenv("COSMOS_KEY")]):
raise ValueError("Faltan variables de entorno: COSMOS_ENDPOINT y COSMOS_KEY")
# Inicializar conexiones a la base de datos
if not initialize_database_connections():
raise ValueError("No se pudo inicializar la conexi贸n a la base de datos")
logger.info("Inicializaci贸n completada exitosamente")
def main():
"""Funci贸n principal que inicia la aplicaci贸n"""
try:
initialize_app()
app = create_router()
app.launch(
server_name="0.0.0.0",
server_port=7860,
show_error=True # Ayuda a depurar
)
except Exception as e:
logger.error(f"Error iniciando la aplicaci贸n: {str(e)}")
raise
if __name__ == "__main__":
main() |