main.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import uvicorn
  3. from app import create_app, setup_routes
  4. from config.settings import PORT, OPENAI_API_KEY, BG_DATA_PATH, validate_config
  5. from logging import getLogger
  6. from threading import Thread
  7. from services.data_service import initialize_db
  8. logger = getLogger("main")
  9. def main():
  10. """Main application entry point"""
  11. # Validate configuration
  12. if not validate_config():
  13. logger.critical("FATAL: Configuration validation failed.")
  14. if not OPENAI_API_KEY:
  15. logger.error("Please create a .env file with OPENAI_API_KEY='your_key_here'")
  16. with open(".env", "w") as f:
  17. f.write("OPENAI_API_KEY='your_key_here'")
  18. return
  19. # Create and configure app
  20. app = create_app()
  21. setup_routes(app)
  22. initialize_db()
  23. # Display startup information
  24. logger.info(f"Servidor corriendo en http://localhost:{PORT}")
  25. if not os.path.exists(BG_DATA_PATH):
  26. logger.warning(f"ADVERTENCIA: {BG_DATA_PATH} no encontrado. El asistente de IA no tendrá datos específicos del menú.")
  27. else:
  28. logger.info(f"Datos del asistente cargados desde: {os.path.abspath(BG_DATA_PATH)}")
  29. # Start the server
  30. #rut without logs
  31. return app
  32. app = main()
  33. if not app:
  34. logger.critical("FATAL: Failed to create FastAPI app.")
  35. exit(1)
  36. if __name__ == "__main__":
  37. uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="info", access_log=False)