Spaces:
Sleeping
Sleeping
Download main.py from ranbyDipz/BTP-Intelligence-Engine: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/ranbyDipz/BTP-Intelligence-Engine/resolve/main/main.py
- Command line
-
hf download hf://spaces/ranbyDipz/BTP-Intelligence-Engine/main.py
-
curl -L -o main.py https://huggingface.co/spaces/ranbyDipz/BTP-Intelligence-Engine/resolve/main/main.py
1.39 kB
| 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.") | |