import streamlit as st import numpy as np import joblib # Page configuration st.set_page_config( page_title="HDD Predictor", page_icon="🔧", layout="centered", initial_sidebar_state="collapsed" ) # Ultra-minimal Canva-style CSS st.markdown(""" """, unsafe_allow_html=True) # Load model @st.cache_resource def load_model(): try: model = joblib.load('decision_tree_model.pkl') le_soil = joblib.load('dt_soil_encoder.pkl') le_water = joblib.load('dt_water_encoder.pkl') le_solution = joblib.load('dt_solution_encoder.pkl') return model, le_soil, le_water, le_solution except FileNotFoundError: st.error("Model files not found!") return None, None, None, None def predict_solution(diameter, soil_type, high_water, model, le_soil, le_water, le_solution): try: soil_encoded = le_soil.transform([soil_type])[0] water_encoded = le_water.transform([high_water])[0] features = np.array([[diameter, soil_encoded, water_encoded]]) prediction_encoded = model.predict(features)[0] prediction = le_solution.inverse_transform([prediction_encoded])[0] return prediction except Exception as e: return f"Error: {str(e)}" def main(): # Logo section st.markdown('', unsafe_allow_html=True) # Container start st.markdown('
', unsafe_allow_html=True) # Header st.markdown('
🔧 HDD Predictor
', unsafe_allow_html=True) st.markdown('
Quick drilling solution recommendation
', unsafe_allow_html=True) # Load model model_data = load_model() if model_data[0] is None: st.stop() model, le_soil, le_water, le_solution = model_data # Inputs diameter = st.slider("Diameter (m)", 0.5, 2.0, 1.2, 0.1) soil_type = st.selectbox("Soil", ['clay', 'sand']) high_water = st.selectbox("High Water", ['no', 'yes']) # Predict if st.button("Get Solution"): prediction = predict_solution(diameter, soil_type, high_water, model, le_soil, le_water, le_solution) solutions = { 'A': {'icon': '🛡️', 'title': 'Enhanced Protection', 'desc': 'Sheetpile + Trench + Grouting', 'class': 'sol-a'}, 'B': {'icon': '🏰', 'title': 'Maximum Protection', 'desc': 'Full System + Casing', 'class': 'sol-b'}, 'C': {'icon': '🔨', 'title': 'Moderate Protection', 'desc': 'Sheetpile + Trench', 'class': 'sol-c'}, 'D': {'icon': '💧', 'title': 'Basic Protection', 'desc': 'Grouting Only', 'class': 'sol-d'}, 'E': {'icon': '✅', 'title': 'Minimal Action', 'desc': 'No Additional Measures', 'class': 'sol-e'} } if prediction in solutions: sol = solutions[prediction] st.markdown(f'''
{sol['icon']}
Solution {prediction}
{sol['title']}
{sol['desc']}
''', unsafe_allow_html=True) # Container end st.markdown('
', unsafe_allow_html=True) if __name__ == "__main__": main()