vihu21 commited on
Commit
08e5cd0
·
verified ·
1 Parent(s): 46a132c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +68 -50
app.py CHANGED
@@ -1,60 +1,78 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
  import joblib
4
  from huggingface_hub import hf_hub_download
 
 
5
 
6
- # ----------------------------
7
- # Load model from Hugging Face
8
- # ----------------------------
9
- HF_MODEL_REPO = "vihu21/predictive_maintenance"
10
- MODEL_FILE = "best_ada_model.joblib"
11
-
12
- model_path = hf_hub_download(
13
- repo_id="vihu21/predictive_maintenance",
14
- filename="best_ada_model.joblib",
15
- repo_type="model"
16
- )
17
-
18
- model = joblib.load(model_path)
19
-
20
- # ----------------------------
21
- # Streamlit UI
22
- # ----------------------------
23
- st.title("🔧 Engine Condition Prediction")
24
- st.write("Fill in the engine parameters to predict engine condition.")
25
-
26
- # ----------------------------
27
- # User Inputs
28
- # ----------------------------
29
- engine_rpm = st.number_input("Engine RPM", min_value=50, max_value=6000, value=3000)
30
- lub_oil_pressure = st.number_input("Lub Oil Pressure", min_value=0.0, value=7.25)
31
- fuel_pressure = st.number_input("Fuel Pressure", min_value=0.0, value=21.4)
32
- coolant_pressure = st.number_input("Coolant Pressure", min_value=0.0, value=7.5)
33
- lub_oil_temp = st.number_input("Lub Oil Temperature", min_value=50.0, value=90.0)
34
- coolant_temp = st.number_input("Coolant Temperature", min_value=60.0, value=195.0)
35
-
36
- # ----------------------------
37
- # Prepare input data
38
- # ⚠️ Column names must EXACTLY match training
39
- # ----------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  input_data = pd.DataFrame([{
41
- "Engine rpm": engine_rpm,
42
- "Lub oil pressure": lub_oil_pressure,
43
- "Fuel pressure": fuel_pressure,
44
- "Coolant pressure": coolant_pressure,
45
- "lub oil temp": lub_oil_temp,
46
- "Coolant temp": coolant_temp
47
  }])
48
 
49
- # ----------------------------
50
- # Prediction
51
- # ----------------------------
52
  if st.button("Predict Engine Condition"):
53
- prediction = model.predict(input_data)[0]
54
-
55
- st.subheader("Prediction Result")
 
 
 
56
 
57
- if prediction == 1 or prediction == "Good":
58
- st.success("✅ Engine Condition: GOOD")
59
- else:
60
- st.error("⚠️ Engine Condition: BAD")
 
1
+ # %%writefile app.py
2
  import streamlit as st
3
  import pandas as pd
4
  import joblib
5
  from huggingface_hub import hf_hub_download
6
+ from sklearn.ensemble import AdaBoostClassifier # ensure scikit-learn flavor
7
+ from sklearn.metrics import classification_report
8
 
9
+ # -------------------------------
10
+ # Streamlit App Title & Description
11
+ # -------------------------------
12
+ st.set_page_config(page_title="Engine Condition Predictor", layout="centered")
13
+ st.title("Engine Condition Prediction")
14
+ st.write("""
15
+ Predict if an engine's condition is Good or Bad based on sensor readings.
16
+ """)
17
+
18
+ # -------------------------------
19
+ # Load the model from Hugging Face
20
+ # -------------------------------
21
+
22
+ @st.cache_resource(show_spinner=True)
23
+ def load_model():
24
+ """
25
+ Load the pre-trained AdaBoost model from Hugging Face.
26
+ Uses caching to prevent re-downloading every restart.
27
+ """
28
+ HF_DATASET = "vihu21/predictive_maintenance"
29
+
30
+ MODEL_FILE = "engine_predict/best_ada_model.joblib" # ⚠️ make sure this matches HF exactly
31
+
32
+ model_path = hf_hub_download(
33
+ repo_id=HF_DATASET,
34
+ filename=MODEL_FILE,
35
+ repo_type="model"
36
+ )
37
+ return joblib.load(model_path)
38
+
39
+
40
+
41
+ ada_model = load_model()
42
+ st.success("✅ Model loaded successfully!")
43
+
44
+ # -------------------------------
45
+ # User Input
46
+ # -------------------------------
47
+ st.subheader("Engine Sensor Inputs")
48
+ Engine_Details = st.number_input("Engine Details Size (MB)", min_value=1.0, max_value=4000.0, value=50.0, step=0.1)
49
+ EngineRpm = st.number_input("Engine rpm", min_value=50, max_value=10000, value=3000)
50
+ LubOilPressure = st.number_input("Lubrication Oil Pressure", min_value=0.0, value=7.25)
51
+ FuelPressure = st.number_input("Fuel Pressure", min_value=0.0, value=21.4)
52
+ CoolantPressure = st.number_input("Coolant Pressure", min_value=0.0, value=7.5)
53
+ LubOilTemp = st.number_input("Lubrication Oil Temperature", min_value=0.0, value=90.0)
54
+ CoolantTemp = st.number_input("Coolant Temperature", min_value=0.0, value=195.0)
55
+
56
+ # -------------------------------
57
+ # Prepare input dataframe
58
+ # -------------------------------
59
  input_data = pd.DataFrame([{
60
+ 'Engine rpm': EngineRpm,
61
+ 'Lub oil pressure': LubOilPressure,
62
+ 'Fuel pressure': FuelPressure,
63
+ 'Coolant pressure': CoolantPressure,
64
+ 'lub oil temp': LubOilTemp,
65
+ 'Coolant temp': CoolantTemp
66
  }])
67
 
68
+ # -------------------------------
69
+ # Make Prediction
70
+ # -------------------------------
71
  if st.button("Predict Engine Condition"):
72
+ try:
73
+ prediction = ada_model.predict(input_data)[0]
74
+ st.subheader("Prediction Result")
75
+ st.success(f"Estimated Engine Condition: **{prediction}**")
76
+ except Exception as e:
77
+ st.error(f"❌ Error during prediction: {str(e)}")
78