csankaran3 commited on
Commit
dcd367f
·
verified ·
1 Parent(s): dfcc852

Update app.py

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