Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,15 +6,16 @@ from huggingface_hub import hf_hub_download
|
|
| 6 |
|
| 7 |
|
| 8 |
# ----------------------------------------------------
|
| 9 |
-
# Load trained model
|
| 10 |
# ----------------------------------------------------
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
model = joblib.load(MODEL_PATH)
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
# ----------------------------------------------------
|
| 19 |
# Page Config
|
| 20 |
# ----------------------------------------------------
|
|
@@ -28,6 +29,7 @@ st.markdown("Enter live sensor values to predict engine condition.")
|
|
| 28 |
|
| 29 |
st.divider()
|
| 30 |
|
|
|
|
| 31 |
# ----------------------------------------------------
|
| 32 |
# Sidebar Inputs
|
| 33 |
# ----------------------------------------------------
|
|
@@ -36,43 +38,50 @@ st.sidebar.header("Sensor Inputs")
|
|
| 36 |
engine_rpm = st.sidebar.number_input("Engine RPM", min_value=0.0, value=1500.0)
|
| 37 |
|
| 38 |
lub_oil_pressure = st.sidebar.number_input(
|
| 39 |
-
"Lub Oil Pressure
|
| 40 |
)
|
| 41 |
|
| 42 |
fuel_pressure = st.sidebar.number_input(
|
| 43 |
-
"Fuel Pressure
|
| 44 |
)
|
| 45 |
|
| 46 |
coolant_pressure = st.sidebar.number_input(
|
| 47 |
-
"Coolant Pressure
|
| 48 |
)
|
| 49 |
|
| 50 |
lub_oil_temp = st.sidebar.number_input(
|
| 51 |
-
"Lub Oil Temperature
|
| 52 |
)
|
| 53 |
|
| 54 |
coolant_temp = st.sidebar.number_input(
|
| 55 |
-
"Coolant Temperature
|
| 56 |
)
|
| 57 |
|
|
|
|
| 58 |
# ----------------------------------------------------
|
| 59 |
# Prediction
|
| 60 |
# ----------------------------------------------------
|
| 61 |
if st.button("Predict Engine Condition"):
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
prediction =
|
| 76 |
|
| 77 |
st.subheader("Prediction Result")
|
| 78 |
|
|
@@ -81,17 +90,13 @@ if st.button("Predict Engine Condition"):
|
|
| 81 |
else:
|
| 82 |
st.error("Engine Condition: FAULTY / AT RISK")
|
| 83 |
|
|
|
|
|
|
|
| 84 |
st.divider()
|
| 85 |
|
| 86 |
st.write("### Input Summary")
|
| 87 |
-
st.table(
|
| 88 |
-
|
| 89 |
-
"Lub oil pressure": [lub_oil_pressure],
|
| 90 |
-
"Fuel pressure": [fuel_pressure],
|
| 91 |
-
"Coolant pressure": [coolant_pressure],
|
| 92 |
-
"lub oil temp": [lub_oil_temp],
|
| 93 |
-
"Coolant temp": [coolant_temp],
|
| 94 |
-
})
|
| 95 |
|
| 96 |
# ----------------------------------------------------
|
| 97 |
# Footer
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
# ----------------------------------------------------
|
| 9 |
+
# Load trained model
|
| 10 |
# ----------------------------------------------------
|
| 11 |
+
MODEL_PATH = hf_hub_download(
|
| 12 |
+
repo_id="raj2261992/predictive_maintenance_model",
|
| 13 |
+
filename="engine_condition_xgboost_v1.joblib"
|
| 14 |
+
)
|
| 15 |
|
| 16 |
model = joblib.load(MODEL_PATH)
|
| 17 |
|
| 18 |
|
|
|
|
| 19 |
# ----------------------------------------------------
|
| 20 |
# Page Config
|
| 21 |
# ----------------------------------------------------
|
|
|
|
| 29 |
|
| 30 |
st.divider()
|
| 31 |
|
| 32 |
+
|
| 33 |
# ----------------------------------------------------
|
| 34 |
# Sidebar Inputs
|
| 35 |
# ----------------------------------------------------
|
|
|
|
| 38 |
engine_rpm = st.sidebar.number_input("Engine RPM", min_value=0.0, value=1500.0)
|
| 39 |
|
| 40 |
lub_oil_pressure = st.sidebar.number_input(
|
| 41 |
+
"Lub Oil Pressure", min_value=0.0, value=3.5
|
| 42 |
)
|
| 43 |
|
| 44 |
fuel_pressure = st.sidebar.number_input(
|
| 45 |
+
"Fuel Pressure", min_value=0.0, value=4.0
|
| 46 |
)
|
| 47 |
|
| 48 |
coolant_pressure = st.sidebar.number_input(
|
| 49 |
+
"Coolant Pressure", min_value=0.0, value=2.0
|
| 50 |
)
|
| 51 |
|
| 52 |
lub_oil_temp = st.sidebar.number_input(
|
| 53 |
+
"Lub Oil Temperature", min_value=0.0, value=80.0
|
| 54 |
)
|
| 55 |
|
| 56 |
coolant_temp = st.sidebar.number_input(
|
| 57 |
+
"Coolant Temperature", min_value=0.0, value=75.0
|
| 58 |
)
|
| 59 |
|
| 60 |
+
|
| 61 |
# ----------------------------------------------------
|
| 62 |
# Prediction
|
| 63 |
# ----------------------------------------------------
|
| 64 |
if st.button("Predict Engine Condition"):
|
| 65 |
|
| 66 |
+
# IMPORTANT: Must be DataFrame (not NumPy)
|
| 67 |
+
input_data = pd.DataFrame([{
|
| 68 |
+
"Engine rpm": float(engine_rpm),
|
| 69 |
+
"Lub oil pressure": float(lub_oil_pressure),
|
| 70 |
+
"Fuel pressure": float(fuel_pressure),
|
| 71 |
+
"Coolant pressure": float(coolant_pressure),
|
| 72 |
+
"lub oil temp": float(lub_oil_temp),
|
| 73 |
+
"Coolant temp": float(coolant_temp),
|
| 74 |
+
}])
|
| 75 |
|
| 76 |
+
# Debug display (optional)
|
| 77 |
+
st.write("### Input Data")
|
| 78 |
+
st.write(input_data)
|
| 79 |
|
| 80 |
+
# Predict probability
|
| 81 |
+
prob = model.predict_proba(input_data)[0][1]
|
| 82 |
|
| 83 |
+
threshold = 0.45
|
| 84 |
+
prediction = int(prob >= threshold)
|
| 85 |
|
| 86 |
st.subheader("Prediction Result")
|
| 87 |
|
|
|
|
| 90 |
else:
|
| 91 |
st.error("Engine Condition: FAULTY / AT RISK")
|
| 92 |
|
| 93 |
+
st.metric("Failure Probability", f"{prob:.2%}")
|
| 94 |
+
|
| 95 |
st.divider()
|
| 96 |
|
| 97 |
st.write("### Input Summary")
|
| 98 |
+
st.table(input_data)
|
| 99 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
# ----------------------------------------------------
|
| 102 |
# Footer
|