SabarnaDeb commited on
Commit
f7472e2
·
verified ·
1 Parent(s): ead4136

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ st.set_page_config(page_title="Predictive Maintenance – Engine Health", layout="centered")
7
+
8
+ st.title("Predictive Maintenance – Engine Health")
9
+ st.write("Enter engine sensor readings to predict whether maintenance is needed.")
10
+
11
+ MODEL_REPO = "SabarnaDeb/Capstone_PredictiveMaintenance_Model"
12
+ MODEL_FILE = "model.joblib"
13
+
14
+ @st.cache_resource
15
+ def load_model():
16
+ model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, repo_type="model")
17
+ return joblib.load(model_path)
18
+
19
+ model = load_model()
20
+
21
+ FEATURES = [
22
+ "engine_rpm",
23
+ "lub_oil_pressure",
24
+ "fuel_pressure",
25
+ "coolant_pressure",
26
+ "lub_oil_temperature",
27
+ "coolant_temperature"
28
+ ]
29
+
30
+ engine_rpm = st.number_input("Engine RPM", value=800.0)
31
+ lub_oil_pressure = st.number_input("Lub Oil Pressure", value=4.0)
32
+ fuel_pressure = st.number_input("Fuel Pressure", value=6.5)
33
+ coolant_pressure = st.number_input("Coolant Pressure", value=3.5)
34
+ lub_oil_temperature = st.number_input("Lub Oil Temperature", value=80.0)
35
+ coolant_temperature = st.number_input("Coolant Temperature", value=85.0)
36
+
37
+ if st.button("Predict"):
38
+ input_df = pd.DataFrame([{
39
+ "engine_rpm": engine_rpm,
40
+ "lub_oil_pressure": lub_oil_pressure,
41
+ "fuel_pressure": fuel_pressure,
42
+ "coolant_pressure": coolant_pressure,
43
+ "lub_oil_temperature": lub_oil_temperature,
44
+ "coolant_temperature": coolant_temperature,
45
+ }])
46
+
47
+ pred = int(model.predict(input_df[FEATURES])[0])
48
+
49
+ prob = None
50
+ if hasattr(model, "predict_proba"):
51
+ prob = float(model.predict_proba(input_df[FEATURES])[:, 1][0])
52
+
53
+ st.subheader("Prediction Result")
54
+ if pred == 1:
55
+ st.error("⚠️ Maintenance Needed")
56
+ else:
57
+ st.success("✅ Normal Operation")
58
+
59
+ if prob is not None:
60
+ st.write(f"Confidence (maintenance probability): **{prob:.2f}**")
61
+
62
+ st.subheader("Input Data (saved as DataFrame)")
63
+ st.dataframe(input_df)