-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_web_ui.py
More file actions
66 lines (52 loc) · 2.13 KB
/
run_web_ui.py
File metadata and controls
66 lines (52 loc) · 2.13 KB
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
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Stock Simulation Web UI Launcher
-------------------------------
Launch the web interface for running stock price simulations.
"""
import os
import sys
import webbrowser
import time
from threading import Timer
# IMPORTANT: Always use port 8080 for this application
# Port 5000 conflicts with macOS AirPlay Receiver service
# All agents should use port 8080 for consistency
def open_browser():
"""Open browser to the web UI after a short delay."""
webbrowser.open('http://localhost:8080')
if __name__ == "__main__":
# Make sure any existing web server is stopped
try:
import signal
import subprocess
subprocess.run(["pkill", "-f", "python.*run_web"], stderr=subprocess.PIPE)
time.sleep(1) # Give servers time to shutdown
except Exception as e:
print(f"Note: Could not stop existing servers: {e}")
# Create templates directory if it doesn't exist
os.makedirs('templates/static', exist_ok=True)
# Ensure absolute paths for templates
current_dir = os.path.dirname(os.path.abspath(__file__))
template_dir = os.path.join(current_dir, 'templates')
print("\n=== Starting Stock Price Simulation ===")
print(f"Current directory: {current_dir}")
print(f"Template directory: {template_dir}")
# Check if index.html exists
index_path = os.path.join(template_dir, 'index.html')
if os.path.exists(index_path):
print(f"Found index.html: {index_path}")
else:
print(f"WARNING: index.html not found at {index_path}")
# Force Python to look in current directory first for imports
sys.path.insert(0, current_dir)
# Set up to open browser after server starts
Timer(1.5, open_browser).start()
# Import and run the web UI - make sure we're importing the correct one
import web_interface
print(f"Imported web_interface from {web_interface.__file__}")
from web_interface import app
print("Starting web interface for Stock Price Simulation...")
print("Opening browser to http://localhost:8080")
# Run the app
app.run(debug=True, host='0.0.0.0', port=8080)