Shalyn commited on
Commit
443c038
·
verified ·
1 Parent(s): eba542f

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -2,42 +2,39 @@ 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 model hub
7
- model_path = hf_hub_download(repo_id="Shalyn/PredictiveMaintanence-model",filename="engine_condition_model_v1.joblib")
8
 
9
- #loading the model
 
 
 
 
 
10
  model = joblib.load(model_path)
11
 
12
- #Building Streamlit app UI
13
- st.title("Predictive Maintanence Prediction Tool")
14
- st.write("This tool helps to forecast potential failures in vehicles before they occur.")
15
- st.write("Kindly enter the vehicle sensor values to predict if the vehicle needs maintanence.")
 
 
 
16
 
17
- #collect user input
18
- Engine_RPM = st.number_input("Engine_RPM(The number of revolutions per minute (RPM) of the engine, indicating engine speed. It is defined in Revolutions per Minute (RPM))")
19
- Lub_Oil_Pressure = st.number_input("Lub_Oil_Pressure (The pressure of the lubricating oil in the engine, essential for reducing friction and wear. It is defined in bar or kilopascals (kPa))")
20
- Fuel_Pressure = st.number_input("Fuel_Pressure (The pressure at which fuel is supplied to the engine, critical for proper combustion. It is defined in bar or kilopascals (kPa))")
21
- Coolant_Pressure = st.number_input("Coolant_Pressure (The pressure of the engine coolant, affecting engine temperature regulation. It is defined in bar or kilopascals (kPa) )")
22
- Lub_Oil_Temperature = st.number_input("Lub_Oil_Temperature (The temperature of the lubricating oil, which impacts viscosity and engine performance. It is defined in degrees Celsius (°C) )")
23
- Coolant_Temperature = st.number_input("Coolant_Temperature (The temperature of the engine coolant, crucial for preventing overheating. It is defined in degrees Celsius (°C))")
24
-
25
- #Converting the inputs to match training datarow
26
  input_data = pd.DataFrame([{
27
  'Engine rpm': Engine_RPM,
28
  'Lub oil pressure': Lub_Oil_Pressure,
29
  'Fuel pressure': Fuel_Pressure,
30
  'Coolant pressure': Coolant_Pressure,
31
- 'lub oil temp' : Lub_Oil_Temperature,
32
  'Coolant temp': Coolant_Temperature
33
  }])
34
 
35
- #setting up classification threshold
36
  classification_threshold = 0.45
37
-
38
- #Creating prediction button
39
  if st.button("Predict"):
40
- prediction_prob = model.predict_proba(input_data)[0,1]
41
- prediction = (prediction_prob>classification_threshold).astype(int)
42
- result = "Off/False/Active" if prediction == 0 else "On/True/Faulty"
43
- st.write(f"Based on the given input the vehicle is {result}")
 
2
  import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
+ import os
6
 
7
+ st.title("Predictive Maintenance Prediction Tool")
 
8
 
9
+ # Load model
10
+ model_path = hf_hub_download(
11
+ repo_id="Shalyn/PredictiveMaintanence-model",
12
+ filename="engine_condition_model_v1.joblib",
13
+ token=os.getenv("HF_TOKEN")
14
+ )
15
  model = joblib.load(model_path)
16
 
17
+ # User input
18
+ Engine_RPM = st.number_input("Engine RPM", min_value=0)
19
+ Lub_Oil_Pressure = st.number_input("Lub Oil Pressure")
20
+ Fuel_Pressure = st.number_input("Fuel Pressure")
21
+ Coolant_Pressure = st.number_input("Coolant Pressure")
22
+ Lub_Oil_Temperature = st.number_input("Lub Oil Temperature")
23
+ Coolant_Temperature = st.number_input("Coolant Temperature")
24
 
 
 
 
 
 
 
 
 
 
25
  input_data = pd.DataFrame([{
26
  'Engine rpm': Engine_RPM,
27
  'Lub oil pressure': Lub_Oil_Pressure,
28
  'Fuel pressure': Fuel_Pressure,
29
  'Coolant pressure': Coolant_Pressure,
30
+ 'lub oil temp': Lub_Oil_Temperature,
31
  'Coolant temp': Coolant_Temperature
32
  }])
33
 
34
+ # Prediction
35
  classification_threshold = 0.45
 
 
36
  if st.button("Predict"):
37
+ prediction_prob = model.predict_proba(input_data)[0,1]
38
+ prediction = int(prediction_prob > classification_threshold)
39
+ result = "Off/False/Active" if prediction == 0 else "On/True/Faulty"
40
+ st.write(f"Vehicle status: **{result}**")