#!/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()