blob: 23d84bd1b6adafe8fb35f755c2f0ea1c8c0f1cb0 [file] [log] [blame]
#!/usr/bin/env python3
"""
SimExR Streamlit App Launcher
This script starts the Streamlit app with the correct configuration.
Make sure the API server is running before starting the Streamlit app.
"""
import subprocess
import sys
import time
import requests
from pathlib import Path
def check_api_server():
"""Check if the API server is running."""
try:
response = requests.get("http://127.0.0.1:8000/health/status", timeout=5)
return response.status_code == 200
except:
return False
def main():
print("šŸš€ SimExR Streamlit App Launcher")
print("=" * 40)
# Check if API server is running
print("šŸ” Checking API server status...")
if not check_api_server():
print("āŒ API server is not running!")
print("šŸ’” Please start the API server first with:")
print(" python start_api.py --host 127.0.0.1 --port 8000")
print("\nšŸ”„ Starting API server automatically...")
# Try to start the API server
try:
api_process = subprocess.Popen([
sys.executable, "start_api.py", "--host", "127.0.0.1", "--port", "8000"
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for server to start
print("ā³ Waiting for API server to start...")
for i in range(30): # Wait up to 30 seconds
time.sleep(1)
if check_api_server():
print("āœ… API server started successfully!")
break
else:
print("āŒ Failed to start API server")
return 1
except Exception as e:
print(f"āŒ Error starting API server: {e}")
return 1
else:
print("āœ… API server is running!")
# Check if app.py exists
if not Path("app.py").exists():
print("āŒ app.py not found!")
print("šŸ’” Make sure you're in the correct directory")
return 1
# Start Streamlit app
print("\n🌐 Starting Streamlit app...")
print("šŸ“± The app will be available at: http://localhost:8501")
print("šŸ”— API server: http://127.0.0.1:8000")
print("\n" + "=" * 40)
try:
# Start Streamlit with the app
subprocess.run([
sys.executable, "-m", "streamlit", "run", "app.py",
"--server.port", "8501",
"--server.address", "localhost",
"--browser.gatherUsageStats", "false"
])
except KeyboardInterrupt:
print("\nšŸ›‘ Streamlit app stopped by user")
except Exception as e:
print(f"āŒ Error starting Streamlit app: {e}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())