Files
auracaster-webui/main_mock.py

78 lines
2.5 KiB
Python

"""
Main entry point for the Airport Announcement System.
This script starts both the backend API and the Streamlit frontend.
"""
import subprocess
import sys
import time
import os
import threading
from pathlib import Path
def stream_output(process, prefix):
"""Stream the output of a process to the console in real-time."""
for line in iter(process.stdout.readline, ''):
if line:
print(f"{prefix}: {line.strip()}")
for line in iter(process.stderr.readline, ''):
if line:
print(f"{prefix} ERROR: {line.strip()}")
def start_backend():
"""Start the backend API server."""
print("Starting backend API server...")
backend_process = subprocess.Popen(
[sys.executable, "-m", "uvicorn", "mock_backend.mock_api:app", "--host", "0.0.0.0", "--port", "7999", "--reload"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1 # Line buffered
)
# Start a thread to stream the backend output
backend_thread = threading.Thread(target=stream_output, args=(backend_process, "BACKEND"), daemon=True)
backend_thread.start()
# Wait a moment to ensure the backend has started
time.sleep(2)
return backend_process
def start_frontend():
"""Start the Streamlit frontend."""
print("Starting Streamlit frontend...")
frontend_process = subprocess.Popen(
[sys.executable, "-m", "streamlit", "run", "auracaster-webui.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1 # Line buffered
)
# Start a thread to stream the frontend output
frontend_thread = threading.Thread(target=stream_output, args=(frontend_process, "FRONTEND"), daemon=True)
frontend_thread.start()
return frontend_process
if __name__ == "__main__":
# Ensure we're in the correct directory
os.chdir(Path(__file__).parent)
# Start the backend and frontend
backend_process = start_backend()
frontend_process = start_frontend()
print("Airport Announcement System is running!")
print("Backend API: http://localhost:7999")
print("Frontend: http://localhost:8501")
try:
# Keep the main process running
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down Airport Announcement System...")
backend_process.terminate()
frontend_process.terminate()
print("Shutdown complete.")