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