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