| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import os
- import uvicorn
- from app import create_app, setup_routes
- from config.settings import PORT, OPENAI_API_KEY, BG_DATA_PATH, validate_config
- from logging import getLogger
- from threading import Thread
- from services.data_service import initialize_db
- logger = getLogger("main")
- def main():
- """Main application entry point"""
- # Validate configuration
- if not validate_config():
- logger.critical("FATAL: Configuration validation failed.")
- if not OPENAI_API_KEY:
- logger.error("Please create a .env file with OPENAI_API_KEY='your_key_here'")
- with open(".env", "w") as f:
- f.write("OPENAI_API_KEY='your_key_here'")
- return
-
- # Create and configure app
- app = create_app()
- setup_routes(app)
- initialize_db()
-
- # Display startup information
- logger.info(f"Servidor corriendo en http://localhost:{PORT}")
- if not os.path.exists(BG_DATA_PATH):
- logger.warning(f"ADVERTENCIA: {BG_DATA_PATH} no encontrado. El asistente de IA no tendrá datos específicos del menú.")
- else:
- logger.info(f"Datos del asistente cargados desde: {os.path.abspath(BG_DATA_PATH)}")
- # Start the server
- #rut without logs
- return app
- app = main()
- if not app:
- logger.critical("FATAL: Failed to create FastAPI app.")
- exit(1)
- if __name__ == "__main__":
- uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info", access_log=False)
|