csankaran3 commited on
Commit
b3b92af
·
verified ·
1 Parent(s): bb526ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -120
app.py CHANGED
@@ -1,140 +1,54 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
- import joblib
4
  from huggingface_hub import hf_hub_download
 
5
 
6
- # --------------------------------------------------
7
- # Page Configuration
8
- # --------------------------------------------------
9
- st.set_page_config(
10
- page_title="Predictive Maintenance | Engine Health",
11
- page_icon="🛠️",
12
- layout="centered"
13
- )
14
-
15
- # --------------------------------------------------
16
- # Load Model (cached)
17
- # --------------------------------------------------
18
- @st.cache_resource
19
- def load_model():
20
- model_path = hf_hub_download(
21
- repo_id="csankaran3/engine-condition-prediction",
22
- filename="best_engine_condition_prediction_model_v1.joblib"
23
- )
24
- return joblib.load(model_path)
25
-
26
- model = load_model()
27
-
28
- # --------------------------------------------------
29
- # Header
30
- # --------------------------------------------------
31
- st.title("🛠️ Predictive Maintenance – Engine Condition")
32
- st.markdown(
33
- """
34
- This **internal diagnostic tool** helps automobile companies
35
- predict **engine health (Active / Faulty)** using real-time sensor values.
36
- """
37
- )
38
-
39
- st.divider()
40
-
41
- # --------------------------------------------------
42
- # Sidebar – Sensor Inputs
43
- # --------------------------------------------------
44
- st.sidebar.header("📊 Sensor Inputs")
45
-
46
- engine_rpm = st.sidebar.number_input(
47
- "Engine RPM",
48
- min_value=0.0,
49
- value=1150.0,
50
- step=10.0,
51
- help="Rotational speed of the engine"
52
- )
53
-
54
- lub_oil_pressure = st.sidebar.number_input(
55
- "Lub Oil Pressure (kPa)",
56
- min_value=0.0,
57
- value=3.63,
58
- step=0.01
59
- )
60
 
61
- fuel_pressure = st.sidebar.number_input(
62
- "Fuel Pressure (kPa)",
63
- min_value=0.0,
64
- value=10.57,
65
- step=0.01
66
- )
67
 
68
- coolant_pressure = st.sidebar.number_input(
69
- "Coolant Pressure (kPa)",
70
- min_value=0.0,
71
- value=7.48,
72
- step=0.01
73
- )
74
 
75
- lub_oil_temp = st.sidebar.number_input(
76
- "Lub Oil Temperature (°C)",
77
- min_value=0.0,
78
- value=89.58,
79
- step=0.01
80
- )
 
81
 
82
- coolant_temp = st.sidebar.number_input(
83
- "Coolant Temperature (°C)",
84
- min_value=0.0,
85
- value=128.60,
86
- step=0.01
87
- )
88
 
89
- # --------------------------------------------------
90
- # Prepare Input Data
91
- # --------------------------------------------------
92
  input_data = pd.DataFrame([{
93
- "Engine rpm": engine_rpm,
94
- "Lub oil pressure": lub_oil_pressure,
95
- "Fuel pressure": fuel_pressure,
96
- "Coolant pressure": coolant_pressure,
97
- "lub oil temp": lub_oil_temp,
98
- "Coolant temp": coolant_temp
99
  }])
100
 
101
- # --------------------------------------------------
102
- # Prediction Section
103
- # --------------------------------------------------
104
- st.subheader("🔍 Engine Condition Prediction")
105
-
106
  classification_threshold = 0.45
107
 
 
108
  if st.button("🚀 Predict Engine Condition", use_container_width=True):
109
- with st.spinner("Analyzing sensor data..."):
110
- prediction_proba = model.predict_proba(input_data)[0, 1]
111
- prediction = int(prediction_proba >= classification_threshold)
112
-
113
- st.divider()
114
-
115
- col1, col2 = st.columns(2)
116
-
117
- with col1:
118
- st.metric(
119
- label="Fault Probability",
120
- value=f"{prediction_proba:.2%}"
121
- )
122
-
123
- with col2:
124
- st.metric(
125
- label="Threshold",
126
- value=f"{classification_threshold:.0%}"
127
- )
128
-
129
- st.divider()
130
-
131
- if prediction == 1:
132
  st.success(
133
- " **Engine Status: ACTIVE**\n\n"
134
- "The engine is operating within safe parameters."
135
  )
136
  else:
137
  st.error(
138
- "⚠️ **Engine Status: FAULTY**\n\n"
139
- "Potential fault detected. Immediate inspection recommended."
140
  )
 
1
+ %%writefile mlops/deployment/app.py
2
  import streamlit as st
3
  import pandas as pd
 
4
  from huggingface_hub import hf_hub_download
5
+ import joblib
6
 
7
+ # Download the model from the Model Hub
8
+ model_path = hf_hub_download(repo_id="csankaran3/engine-condition-prediction", filename="best_engine_condition_prediction_model_v1.joblib")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Load the model
11
+ model = joblib.load(model_path)
 
 
 
 
12
 
13
+ # Streamlit UI for Customer Churn Prediction
14
+ st.set_page_config(page_title="Predictive Maintenance", layout="centered")
15
+ st.title("Predictive Maintenance - Engine fault prediction application")
16
+ st.write("This App is an internal tool for automobie companies to predict engine condition (Active / Faulty) based on the sensor values.")
17
+ st.subheader("Kindly enter the sensor details to check whether engine condition is active or faulty.")
18
+ st.subheader("📊 Sensor Inputs")
19
 
20
+ # Setting the display value
21
+ engine_rpm = st.number_input("Engine RPM", min_value=0.0, value=1150.0, step=10.0)
22
+ lub_oil_pressure = st.number_input("Lub Oil Pressure (kPa)", min_value=0.0, value=3.63, step=0.01)
23
+ fuel_pressure = st.number_input("Fuel Pressure (kPa)", min_value=0.0, value=10.57, step=0.01)
24
+ coolant_pressure = st.number_input("Coolant Pressure (kPa)", min_value=0.0, value=7.48, step=0.01)
25
+ lub_oil_temp = st.number_input("Lub Oil Temperature (°C)", min_value=0.32, value=89.58, step=0.01)
26
+ coolant_temp = st.number_input("Coolant Temperature (°C)", min_value=0.67, value=128.60, step=0.01)
27
 
 
 
 
 
 
 
28
 
29
+ # Convert inputs to match model training
 
 
30
  input_data = pd.DataFrame([{
31
+ 'Engine rpm': engine_rpm,
32
+ 'Lub oil pressure': lub_oil_pressure,
33
+ 'Fuel pressure': fuel_pressure,
34
+ 'Coolant pressure': coolant_pressure,
35
+ 'lub oil temp': lub_oil_temp,
36
+ 'Coolant temp': coolant_temp
37
  }])
38
 
39
+ # Set the classification threshold
 
 
 
 
40
  classification_threshold = 0.45
41
 
42
+ # Predict button
43
  if st.button("🚀 Predict Engine Condition", use_container_width=True):
44
+ prediction_proba = model.predict_proba(input_data)[0, 1]
45
+ prediction = (prediction_proba >= classification_threshold).astype(int)
46
+ result = "Active" if prediction == 1 else "Faulty"
47
+ if result == "Active":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  st.success(
49
+ f"Engine condition prediction completed!.. **✅ **Engine Status: ACTIVE**\n\n The engine is operating within safe parameters."
 
50
  )
51
  else:
52
  st.error(
53
+ f"Engine condition prediction completed!.. **⚠️ **Engine Status: FAULTY**\n\n Potential fault detected. Immediate inspection recommended."
 
54
  )