Spaces:
Sleeping
Sleeping
Upload main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
from src.data_processor import TrafficDataProcessor
|
| 5 |
+
from src.forecaster import ImpactForecaster
|
| 6 |
+
|
| 7 |
+
def train_models():
|
| 8 |
+
data_path = 'Astram event data_anonymized - Astram event data_anonymizedb40ac87.csv'
|
| 9 |
+
|
| 10 |
+
if not os.path.exists(data_path):
|
| 11 |
+
print(f"Error: Dataset not found at {data_path}")
|
| 12 |
+
return False
|
| 13 |
+
|
| 14 |
+
print("--- Phase 1: Initializing Data Pipeline ---")
|
| 15 |
+
processor = TrafficDataProcessor(data_path)
|
| 16 |
+
df = processor.process()
|
| 17 |
+
|
| 18 |
+
print("\n--- Phase 2: Training ML Forecaster ---")
|
| 19 |
+
forecaster = ImpactForecaster()
|
| 20 |
+
forecaster.train(df)
|
| 21 |
+
|
| 22 |
+
print("\nTraining Complete! Models are ready.")
|
| 23 |
+
return True
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
# Check if models exist
|
| 27 |
+
if not os.path.exists('models/forecaster_model.pkl'):
|
| 28 |
+
success = train_models()
|
| 29 |
+
if not success:
|
| 30 |
+
sys.exit(1)
|
| 31 |
+
else:
|
| 32 |
+
print("Models already exist. Skipping training.")
|
| 33 |
+
|
| 34 |
+
print("\n--- Phase 3: Launching Command Center ---")
|
| 35 |
+
print("Please view the application in your browser.")
|
| 36 |
+
try:
|
| 37 |
+
subprocess.run([sys.executable, "-m", "streamlit", "run", "src/app.py"])
|
| 38 |
+
except KeyboardInterrupt:
|
| 39 |
+
print("Shutting down the Command Center.")
|