File size: 3,129 Bytes
80f87f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
"""
Simple deployment runner for HDD Solution Predictor
"""

import subprocess
import sys
import os
import webbrowser
import time

def check_files():
    """Check if all required files exist"""
    required_files = [
        'app.py',
        'requirements.txt',
        'decision_tree_model.pkl',
        'dt_soil_encoder.pkl',
        'dt_water_encoder.pkl', 
        'dt_solution_encoder.pkl'
    ]
    
    missing = []
    for file in required_files:
        if not os.path.exists(file):
            missing.append(file)
    
    return missing

def install_requirements():
    """Install Python requirements"""
    try:
        print("πŸ“¦ Installing requirements...")
        subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'], 
                      check=True, capture_output=True)
        print("βœ… Requirements installed successfully")
        return True
    except subprocess.CalledProcessError:
        print("❌ Failed to install requirements")
        return False

def run_app(port=8501):
    """Run the Streamlit app"""
    try:
        print(f"πŸš€ Starting HDD Solution Predictor on port {port}...")
        
        # Start streamlit
        process = subprocess.Popen([
            'streamlit', 'run', 'app.py', 
            f'--server.port={port}',
            '--server.address=0.0.0.0'
        ])
        
        # Give it time to start
        time.sleep(3)
        
        # Open browser
        print(f"🌐 Opening browser at http://localhost:{port}")
        webbrowser.open(f'http://localhost:{port}')
        
        print(f"\nβœ… App running at: http://localhost:{port}")
        print("⏹️  Press Ctrl+C to stop")
        
        # Wait for interrupt
        try:
            process.wait()
        except KeyboardInterrupt:
            print("\nπŸ›‘ Stopping application...")
            process.terminate()
            
    except FileNotFoundError:
        print("❌ Streamlit not found. Installing...")
        subprocess.run([sys.executable, '-m', 'pip', 'install', 'streamlit'])
        print("βœ… Please run again")
        
    except Exception as e:
        print(f"❌ Error: {e}")

def main():
    print("πŸ”§ HDD Solution Predictor - Deployment Runner")
    print("=" * 50)
    
    # Check files
    missing = check_files()
    if missing:
        print("❌ Missing files:")
        for file in missing:
            print(f"   - {file}")
        print("\nπŸ“‹ Please ensure all files are in the deploy directory")
        return
    
    print("βœ… All required files found")
    
    # Check logo
    if os.path.exists('logo2.e8c5ff97.png'):
        print("βœ… MEA logo found")
    else:
        print("⚠️  MEA logo not found (will show text fallback)")
    
    # Install requirements
    print("\nπŸ“¦ Checking requirements...")
    try:
        import streamlit
        print("βœ… Streamlit already installed")
    except ImportError:
        if not install_requirements():
            return
    
    # Run app
    print("\nπŸš€ Launching application...")
    run_app()

if __name__ == "__main__":
    main()