Rizwan9 commited on
Commit
633dcba
·
verified ·
1 Parent(s): 52c06b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -26
app.py CHANGED
@@ -15,7 +15,7 @@ st.set_page_config(
15
 
16
 
17
  # ==============================
18
- # LOAD MODEL (WITH CACHING)
19
  # ==============================
20
 
21
  @st.cache_resource
@@ -31,7 +31,11 @@ def load_model():
31
  return None
32
 
33
 
34
- model = load_model()
 
 
 
 
35
 
36
 
37
  # ==============================
@@ -65,27 +69,39 @@ coolant_temp = st.number_input("Coolant Temperature", 50.0, 150.0, 85.0)
65
 
66
  if st.button("Predict Engine Condition"):
67
 
68
- if model is None:
69
- st.error("Model not loaded. Please check deployment.")
70
- else:
71
- try:
72
- input_data = pd.DataFrame([{
73
- "Engine rpm": engine_rpm,
74
- "Lub oil pressure": lub_oil_pressure,
75
- "Fuel pressure": fuel_pressure,
76
- "Coolant pressure": coolant_pressure,
77
- "Lub oil temp": lub_oil_temp,
78
- "Coolant temp": coolant_temp
79
- }])
80
-
81
- prediction = model.predict(input_data)[0]
82
-
83
- st.subheader("Prediction Result")
84
-
85
- if prediction == 1:
86
- st.error("Engine Failure Likely – Maintenance Required")
87
- else:
88
- st.success("Engine Operating Normally")
89
-
90
- except Exception as e:
91
- st.error(f"Prediction failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
  # ==============================
18
+ # LOAD MODEL
19
  # ==============================
20
 
21
  @st.cache_resource
 
31
  return None
32
 
33
 
34
+ with st.spinner("Loading model..."):
35
+ model = load_model()
36
+
37
+ if model is None:
38
+ st.stop()
39
 
40
 
41
  # ==============================
 
69
 
70
  if st.button("Predict Engine Condition"):
71
 
72
+ try:
73
+ # FIXED COLUMN ORDER
74
+ columns = [
75
+ "Engine rpm",
76
+ "Lub oil pressure",
77
+ "Fuel pressure",
78
+ "Coolant pressure",
79
+ "Lub oil temp",
80
+ "Coolant temp"
81
+ ]
82
+
83
+ input_data = pd.DataFrame([[
84
+ engine_rpm,
85
+ lub_oil_pressure,
86
+ fuel_pressure,
87
+ coolant_pressure,
88
+ lub_oil_temp,
89
+ coolant_temp
90
+ ]], columns=columns)
91
+
92
+ prediction = model.predict(input_data)[0]
93
+
94
+ st.subheader("Prediction Result")
95
+
96
+ # Optional probability
97
+ if hasattr(model, "predict_proba"):
98
+ prob = model.predict_proba(input_data)[0][1]
99
+ st.write(f"Failure Probability: {prob:.2f}")
100
+
101
+ if prediction == 1:
102
+ st.error("Engine Failure Likely – Maintenance Required")
103
+ else:
104
+ st.success("Engine Operating Normally")
105
+
106
+ except Exception as e:
107
+ st.error(f"Prediction failed: {e}")