raj2261992 commited on
Commit
6562e37
·
verified ·
1 Parent(s): f9a571b

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +103 -0
  3. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9
3
+
4
+ # Set the working directory inside the container to /app
5
+ WORKDIR /app
6
+
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
9
+
10
+ # Install Python dependencies listed in requirements.txt
11
+ RUN pip3 install -r requirements.txt
12
+
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
+ ENV HOME=/home/user \
16
+ PATH=/home/user/.local/bin:$PATH
17
+
18
+ WORKDIR $HOME/app
19
+
20
+ COPY --chown=user . $HOME/app
21
+
22
+ # Define the command to run the Streamlit app on port "8501" and make it accessible externally
23
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import joblib
4
+
5
+ # ----------------------------------------------------
6
+ # Load trained model + scaler
7
+ # ----------------------------------------------------
8
+ MODEL_PATH = "model.joblib" # change if different
9
+ SCALER_PATH = "scaler.joblib" # optional
10
+
11
+ model = joblib.load(MODEL_PATH)
12
+
13
+ try:
14
+ scaler = joblib.load(SCALER_PATH)
15
+ use_scaler = True
16
+ except:
17
+ use_scaler = False
18
+
19
+
20
+ # ----------------------------------------------------
21
+ # Page Config
22
+ # ----------------------------------------------------
23
+ st.set_page_config(
24
+ page_title="Engine Health Prediction",
25
+ layout="centered"
26
+ )
27
+
28
+ st.title("🛠️ Predictive Maintenance – Engine Health")
29
+ st.markdown("Enter live sensor values to predict engine condition.")
30
+
31
+ st.divider()
32
+
33
+ # ----------------------------------------------------
34
+ # Sidebar Inputs
35
+ # ----------------------------------------------------
36
+ st.sidebar.header("Sensor Inputs")
37
+
38
+ engine_rpm = st.sidebar.number_input("Engine RPM", min_value=0.0, value=1500.0)
39
+
40
+ lub_oil_pressure = st.sidebar.number_input(
41
+ "Lub Oil Pressure (bar/kPa)", min_value=0.0, value=3.5
42
+ )
43
+
44
+ fuel_pressure = st.sidebar.number_input(
45
+ "Fuel Pressure (bar/kPa)", min_value=0.0, value=4.0
46
+ )
47
+
48
+ coolant_pressure = st.sidebar.number_input(
49
+ "Coolant Pressure (bar/kPa)", min_value=0.0, value=2.0
50
+ )
51
+
52
+ lub_oil_temp = st.sidebar.number_input(
53
+ "Lub Oil Temperature (°C)", min_value=0.0, value=80.0
54
+ )
55
+
56
+ coolant_temp = st.sidebar.number_input(
57
+ "Coolant Temperature (°C)", min_value=0.0, value=75.0
58
+ )
59
+
60
+ # ----------------------------------------------------
61
+ # Prediction
62
+ # ----------------------------------------------------
63
+ if st.button("Predict Engine Condition"):
64
+
65
+ input_data = np.array([[
66
+ engine_rpm,
67
+ lub_oil_pressure,
68
+ fuel_pressure,
69
+ coolant_pressure,
70
+ lub_oil_temp,
71
+ coolant_temp
72
+
73
+ ]])
74
+
75
+ if use_scaler:
76
+ input_data = scaler.transform(input_data)
77
+
78
+ prediction = model.predict(input_data)[0]
79
+
80
+ st.subheader("Prediction Result")
81
+
82
+ if prediction == 0:
83
+ st.success("Engine Condition: NORMAL")
84
+ else:
85
+ st.error("Engine Condition: FAULTY / AT RISK")
86
+
87
+ st.divider()
88
+
89
+ st.write("### Input Summary")
90
+ st.table({
91
+ "Engine RPM": [engine_rpm],
92
+ "Lub Oil Pressure": [lub_oil_pressure],
93
+ "Fuel Pressure": [fuel_pressure],
94
+ "Coolant Pressure": [coolant_pressure],
95
+ "Lub Oil Temp": [lub_oil_temp],
96
+ "Coolant Temp": [coolant_temp],
97
+ })
98
+
99
+ # ----------------------------------------------------
100
+ # Footer
101
+ # ----------------------------------------------------
102
+ st.markdown("---")
103
+ st.caption("Predictive Maintenance Dashboard | Built with Streamlit")
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ huggingface_hub==0.32.6
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.6.0
6
+ xgboost==2.1.4
7
+ mlflow==2.13.0