File size: 1,385 Bytes
dce1488
 
 
 
 
 
 
10e48ce
 
dce1488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10e48ce
 
 
 
 
 
dce1488
 
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
import os
import subprocess
import sys
from src.data_processor import TrafficDataProcessor
from src.forecaster import ImpactForecaster

def train_models():
    data_path = 'traffic_dataset.csv'
    os.makedirs('models', exist_ok=True)    
    if not os.path.exists(data_path):
        print(f"Error: Dataset not found at {data_path}")
        return False
        
    print("--- Phase 1: Initializing Data Pipeline ---")
    processor = TrafficDataProcessor(data_path)
    df = processor.process()
    
    print("\n--- Phase 2: Training ML Forecaster ---")
    forecaster = ImpactForecaster()
    forecaster.train(df)
    
    print("\nTraining Complete! Models are ready.")
    return True

if __name__ == "__main__":
    # Check if models exist
    if not os.path.exists('models/forecaster_model.pkl'):
        success = train_models()
        if not success:
            sys.exit(1)
    else:
        print("Models already exist. Skipping training.")
        
    print("\n--- Phase 3: Launching Command Center ---")
    print("Please view the application in your browser.")
    try:
        subprocess.run([
            sys.executable, "-m", "streamlit", "run", "src/app.py",
            "--server.port=7860",
            "--server.address=0.0.0.0",
            "--server.headless=true"
        ])
    except KeyboardInterrupt:
        print("Shutting down the Command Center.")