RajendrakumarPachaiappan commited on
Commit
627c88d
·
verified ·
1 Parent(s): 77f0576

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. DockerFile +1 -1
  2. README.md +1 -1
  3. app.py +17 -33
DockerFile CHANGED
@@ -12,7 +12,7 @@ RUN pip install --no-cache-dir -r requirements.txt
12
  # Copy the application file
13
  COPY app.py .
14
 
15
- # Expose the port (Hugging Face Spaces default for Streamlit/Gradio is 8501 or 7860, but leaving it general is fine)
16
  EXPOSE 8501
17
 
18
  # Command to run the Streamlit application
 
12
  # Copy the application file
13
  COPY app.py .
14
 
15
+ # Expose the port
16
  EXPOSE 8501
17
 
18
  # Command to run the Streamlit application
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Engine Predictive Maintenance Model
3
  colorFrom: blue
4
  colorTo: green
5
  sdk: streamlit
 
1
  ---
2
+ title: Predict Engine Condition
3
  colorFrom: blue
4
  colorTo: green
5
  sdk: streamlit
app.py CHANGED
@@ -5,19 +5,18 @@ import pandas as pd
5
  import numpy as np
6
  from huggingface_hub import hf_hub_download
7
 
8
- # --- Hugging Face Model Repository Details ---
9
  REPO_ID_MODEL = "RajendrakumarPachaiappan/engine-predictive-model"
10
- # Assuming the best model found in the notebook was Random Forest based on your script
11
- MODEL_FILENAME = "final_random_forest_model.joblib"
12
  SCALER_FILENAME = "standard_scaler.joblib"
13
 
14
- # The six feature columns for input
15
  FEATURE_COLS = [
16
  'Engine_RPM', 'Lub_Oil_Pressure', 'Fuel_Pressure',
17
  'Coolant_Pressure', 'Lub_Oil_Temperature', 'Coolant_Temperature'
18
  ]
19
 
20
- # --- Caching Function to Load Model and Scaler ---
21
  @st.cache_resource
22
  def load_artifacts():
23
  """
@@ -42,34 +41,30 @@ def load_artifacts():
42
  # Load the model and scaler
43
  model, scaler = load_artifacts()
44
 
45
- # --- Streamlit UI Setup ---
46
  st.set_page_config(
47
  page_title="Engine Predictive Maintenance",
48
  layout="centered",
49
  initial_sidebar_state="expanded"
50
  )
51
 
52
- st.title("🚗 Engine Predictive Maintenance Model")
53
  st.markdown(
54
  "Use the sliders below to input the current engine sensor readings and predict "
55
  "if the engine is running **NORMAL (0)** or requires **IMMEDIATE MAINTENANCE (1)**. "
56
  "This model uses a pre-trained Random Forest classifier."
57
  )
58
  st.markdown(
59
- "**Note:** The slider ranges are based on the minimum and maximum values observed in the training dataset (19,535 records)."
60
  )
61
 
62
  if model is None or scaler is None:
63
- st.stop() # Stop the app if artifacts failed to load
64
 
65
- # --- Input Components ---
66
  st.header("Sensor Readings")
67
 
68
-
69
- # Define ranges based on the provided dataset statistics
70
- # Format: (min_value, max_value, mean_value/default) - all values are floats.
71
  ranges = {
72
- 'Engine_RPM': (61.0, 2239.0, 791.0),
73
  'Lub_Oil_Pressure': (0.0, 7.3, 3.3),
74
  'Fuel_Pressure': (0.0, 21.1, 6.7),
75
  'Coolant_Pressure': (0.0, 7.5, 2.3),
@@ -78,17 +73,14 @@ ranges = {
78
  }
79
 
80
  input_values = {}
81
- # Use Streamlit columns for a cleaner, side-by-side layout
82
  col1, col2 = st.columns(2)
83
  columns = [col1, col2]
84
 
85
  for i, col_name in enumerate(FEATURE_COLS):
86
- # Determine which column to place the widget in
87
- current_col = columns[i % 2]
88
 
89
  min_val, max_val, default_val = ranges[col_name]
90
-
91
- # Clean up names for display in the UI and set units
92
  label = col_name.replace('_', ' ')
93
  unit = ""
94
  if "RPM" in col_name:
@@ -109,32 +101,24 @@ for i, col_name in enumerate(FEATURE_COLS):
109
  help=f"Current reading for {label}. Full data range: [{min_val}, {max_val}]"
110
  )
111
 
112
- # --- Prediction Logic ---
113
  if st.button("Predict Engine Condition", type="primary"):
114
- # 1. Prepare data for the model
115
- # Convert input_values dictionary to a DataFrame row
116
  input_df = pd.DataFrame([input_values], columns=FEATURE_COLS)
117
-
118
- # 2. Scale the input data using the pre-trained StandardScaler
119
- # The scaler must be fitted on the same data distribution as the model
120
  input_scaled = scaler.transform(input_df)
121
 
122
- # 3. Make prediction
123
- # The output is a numpy array, we take the first element (the prediction)
124
  prediction = model.predict(input_scaled)[0]
125
-
126
- # 4. Display results
127
  st.subheader("Prediction Result")
128
-
129
  if prediction == 1:
130
  st.error(
131
- "🔴 FAULTY (1): Immediate Maintenance Required! "
132
  "High probability of engine failure detected. Check for high RPM, low pressures, or extreme temperatures."
133
  )
134
  else:
135
  st.success(
136
- "🟢 NORMAL (0): Operating within expected parameters. "
137
  "Engine health is currently good."
138
  )
139
-
140
  st.caption(f"Raw Model Prediction (0=Normal, 1=Faulty): {prediction}")
 
5
  import numpy as np
6
  from huggingface_hub import hf_hub_download
7
 
 
8
  REPO_ID_MODEL = "RajendrakumarPachaiappan/engine-predictive-model"
9
+
10
+ MODEL_FILENAME = "final_random_forest_model.joblib"
11
  SCALER_FILENAME = "standard_scaler.joblib"
12
 
13
+ # Feature Columns for Input
14
  FEATURE_COLS = [
15
  'Engine_RPM', 'Lub_Oil_Pressure', 'Fuel_Pressure',
16
  'Coolant_Pressure', 'Lub_Oil_Temperature', 'Coolant_Temperature'
17
  ]
18
 
19
+ # Caching Function to Load Model and Scaler
20
  @st.cache_resource
21
  def load_artifacts():
22
  """
 
41
  # Load the model and scaler
42
  model, scaler = load_artifacts()
43
 
44
+ # Streamlit Setup
45
  st.set_page_config(
46
  page_title="Engine Predictive Maintenance",
47
  layout="centered",
48
  initial_sidebar_state="expanded"
49
  )
50
 
51
+ st.title("Predict Engine Condition")
52
  st.markdown(
53
  "Use the sliders below to input the current engine sensor readings and predict "
54
  "if the engine is running **NORMAL (0)** or requires **IMMEDIATE MAINTENANCE (1)**. "
55
  "This model uses a pre-trained Random Forest classifier."
56
  )
57
  st.markdown(
58
+ "**Note:** The slider ranges are based on the minimum and maximum values observed in the training dataset"
59
  )
60
 
61
  if model is None or scaler is None:
62
+ st.stop()
63
 
 
64
  st.header("Sensor Readings")
65
 
 
 
 
66
  ranges = {
67
+ 'Engine_RPM': (61.0, 2239.0, 791.0),
68
  'Lub_Oil_Pressure': (0.0, 7.3, 3.3),
69
  'Fuel_Pressure': (0.0, 21.1, 6.7),
70
  'Coolant_Pressure': (0.0, 7.5, 2.3),
 
73
  }
74
 
75
  input_values = {}
 
76
  col1, col2 = st.columns(2)
77
  columns = [col1, col2]
78
 
79
  for i, col_name in enumerate(FEATURE_COLS):
80
+ current_col = columns[i % 2]
 
81
 
82
  min_val, max_val, default_val = ranges[col_name]
83
+
 
84
  label = col_name.replace('_', ' ')
85
  unit = ""
86
  if "RPM" in col_name:
 
101
  help=f"Current reading for {label}. Full data range: [{min_val}, {max_val}]"
102
  )
103
 
104
+ # Prediction Logic
105
  if st.button("Predict Engine Condition", type="primary"):
 
 
106
  input_df = pd.DataFrame([input_values], columns=FEATURE_COLS)
 
 
 
107
  input_scaled = scaler.transform(input_df)
108
 
 
 
109
  prediction = model.predict(input_scaled)[0]
110
+
 
111
  st.subheader("Prediction Result")
112
+
113
  if prediction == 1:
114
  st.error(
115
+ "FAULTY (1): Immediate Maintenance Required! "
116
  "High probability of engine failure detected. Check for high RPM, low pressures, or extreme temperatures."
117
  )
118
  else:
119
  st.success(
120
+ "NORMAL (0): Operating within expected parameters. "
121
  "Engine health is currently good."
122
  )
123
+
124
  st.caption(f"Raw Model Prediction (0=Normal, 1=Faulty): {prediction}")