You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.5 KiB

1 month ago
  1. #!/usr/bin/env python3
  2. """
  3. Kronos Web UI startup script
  4. """
  5. import os
  6. import sys
  7. import subprocess
  8. import webbrowser
  9. import time
  10. def check_dependencies():
  11. """Check if dependencies are installed"""
  12. try:
  13. import flask
  14. import flask_cors
  15. import pandas
  16. import numpy
  17. import plotly
  18. print("✅ All dependencies installed")
  19. return True
  20. except ImportError as e:
  21. print(f"❌ Missing dependency: {e}")
  22. print("Please run: pip install -r requirements.txt")
  23. return False
  24. def install_dependencies():
  25. """Install dependencies"""
  26. print("Installing dependencies...")
  27. try:
  28. subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
  29. print("✅ Dependencies installation completed")
  30. return True
  31. except subprocess.CalledProcessError:
  32. print("❌ Dependencies installation failed")
  33. return False
  34. def main():
  35. """Main function"""
  36. print("🚀 Starting Kronos Web UI...")
  37. print("=" * 50)
  38. # Check dependencies
  39. if not check_dependencies():
  40. print("\nAuto-install dependencies? (y/n): ", end="")
  41. if input().lower() == 'y':
  42. if not install_dependencies():
  43. return
  44. else:
  45. print("Please manually install dependencies and retry")
  46. return
  47. # Check model availability
  48. try:
  49. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  50. from model import Kronos, KronosTokenizer, KronosPredictor
  51. print("✅ Kronos model library available")
  52. model_available = True
  53. except ImportError:
  54. print("⚠️ Kronos model library not available, will use simulated prediction")
  55. model_available = False
  56. # Start Flask application
  57. print("\n🌐 Starting Web server...")
  58. # Set environment variables
  59. os.environ['FLASK_APP'] = 'app.py'
  60. os.environ['FLASK_ENV'] = 'development'
  61. # Start server
  62. try:
  63. from app import app
  64. print("✅ Web server started successfully!")
  65. print(f"🌐 Access URL: http://localhost:7070")
  66. print("💡 Tip: Press Ctrl+C to stop server")
  67. # Auto-open browser
  68. time.sleep(2)
  69. webbrowser.open('http://localhost:7070')
  70. # Start Flask application
  71. app.run(debug=True, host='0.0.0.0', port=7070)
  72. except Exception as e:
  73. print(f"❌ Startup failed: {e}")
  74. print("Please check if port 7070 is occupied")
  75. if __name__ == "__main__":
  76. main()