HDDprediciton / run.py
Sompote's picture
Upload 15 files
80f87f8 verified
#!/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()