File size: 3,069 Bytes
fb61aba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
"""

COVID-19 Prediction Pipeline

---------------------------

This script runs the complete pipeline from data preprocessing to model training

and launches the Gradio UI.

"""

import os
import argparse
import subprocess
import time

def clear_screen():
    """Clear the terminal screen"""
    os.system('cls' if os.name == 'nt' else 'clear')

def run_command(command, description):
    """Run a system command and print output"""
    print(f"\n{'=' * 80}")
    print(f"STEP: {description}")
    print(f"{'=' * 80}\n")
    print(f"Running: {command}\n")
    
    # Run the command
    start_time = time.time()
    result = subprocess.run(command, shell=True)
    end_time = time.time()
    
    # Check if command was successful
    if result.returncode == 0:
        print(f"\nSuccess! Completed in {end_time - start_time:.2f} seconds")
    else:
        print(f"\nError! Command failed with exit code {result.returncode}")
        exit(1)
    
    print(f"\n{'=' * 80}\n")
    time.sleep(1)

def parse_args():
    """Parse command-line arguments"""
    parser = argparse.ArgumentParser(description="COVID-19 Prediction Pipeline")
    parser.add_argument("--skip-preprocessing", action="store_true", help="Skip data preprocessing")
    parser.add_argument("--skip-training", action="store_true", help="Skip model training")
    parser.add_argument("--only-ui", action="store_true", help="Only launch the Gradio UI")
    return parser.parse_args()

def main():
    """Run the complete pipeline"""
    args = parse_args()
    
    # Display welcome banner
    clear_screen()
    print("\n" + "=" * 80)
    print("COVID-19 PREDICTION PIPELINE".center(80))
    print("=" * 80 + "\n")
    print("This script will run the complete pipeline:")
    print("1. Data preprocessing")
    print("2. Model training")
    print("3. Launch Gradio UI for predictions")
    print("\nPress Ctrl+C at any time to stop the pipeline.")
    print()
    
    try:
        # Step 1: Data Preprocessing
        if args.only_ui:
            print("Skipping preprocessing and training, launching UI only...")
        else:
            if not args.skip_preprocessing:
                run_command("python preprocess_data.py", "Data Preprocessing")
            else:
                print("Skipping preprocessing as requested.")
            
            # Step 2: Model Training
            if not args.skip_training:
                run_command("python train_models.py", "Model Training")
            else:
                print("Skipping model training as requested.")
        
        # Step 3: Launch Gradio UI
        print("\nLaunching Gradio UI for predictions...")
        run_command("python gradio_app.py", "Gradio UI Launch")
    
    except KeyboardInterrupt:
        print("\n\nPipeline interrupted by user. Exiting.")
        exit(0)
    
    except Exception as e:
        print(f"\n\nError in pipeline: {str(e)}")
        exit(1)

if __name__ == "__main__":
    main()