| import streamlit as st |
| import pandas as pd |
| import joblib |
| from huggingface_hub import hf_hub_download |
|
|
| st.set_page_config(page_title="Engine Maintenance Predictor", layout="wide") |
| st.title("🚢 Engine Predictive Maintenance") |
|
|
| |
| @st.cache_resource |
| def load_my_model(): |
| |
| |
| REPO_ID = "ranasinghnaveen/engine-condition-predictor" |
| FILENAME = "engine_model.joblib" |
| |
| try: |
| model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME) |
| return joblib.load(model_path) |
| except Exception as e: |
| st.error(f"Error loading model from Hugging Face: {e}") |
| return None |
|
|
| model = load_my_model() |
|
|
| |
| st.sidebar.header("User Input Features") |
| def user_input_features(): |
| |
| rpm = st.sidebar.number_input("Engine RPM", value=800.0) |
| oil_p = st.sidebar.number_input("Lub Oil Pressure", value=3.5) |
| fuel_p = st.sidebar.number_input("Fuel Pressure", value=6.5) |
| cool_p = st.sidebar.number_input("Coolant Pressure", value=2.5) |
| oil_t = st.sidebar.number_input("Lub Oil Temp", value=78.0) |
| cool_t = st.sidebar.number_input("Coolant Temp", value=80.0) |
| |
| |
| data = { |
| 'Engine_RPM': rpm, |
| 'Lub_Oil_Pressure': oil_p, |
| 'Fuel_Pressure': fuel_p, |
| 'Coolant_Pressure': cool_p, |
| 'Lub_Oil_Temp': oil_t, |
| 'Coolant_Temp': cool_t |
| } |
| return pd.DataFrame(data, index=[0]) |
|
|
| df = user_input_features() |
|
|
| |
| st.subheader('User Input Parameters') |
| st.write(df) |
|
|
| |
| if st.button("Predict"): |
| if model is not None: |
| prediction = model.predict(df) |
| |
| result = "Maintenance Required" if prediction[0] == 0 else "Normal" |
| |
| if prediction[0] == 0: |
| st.error(f"Prediction: {result}") |
| else: |
| st.success(f"Prediction: {result}") |
| else: |
| st.warning("Model not loaded. Please check the repository ID.") |
|
|