Anusha3 commited on
Commit
b42d867
·
verified ·
1 Parent(s): 344bf07

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -20
  2. app.py +26 -38
  3. requirements.txt +4 -4
Dockerfile CHANGED
@@ -1,30 +1,23 @@
1
- # Use Python 3.9 base image
2
  FROM python:3.9
3
 
4
- # Create user
5
- RUN useradd -m -u 1000 user
6
-
7
- # Set working directory
8
- WORKDIR /home/user/app
9
-
10
- # Copy requirements first (better caching)
11
- COPY requirements.txt .
12
 
13
- # Install dependencies
14
- RUN pip install --no-cache-dir -r requirements.txt
15
 
16
- # Copy the rest of the app
17
- COPY --chown=user . .
18
 
19
- # Set environment
 
20
  ENV HOME=/home/user \
21
- PATH=/home/user/.local/bin:$PATH
22
 
23
- # Switch to non-root user
24
- USER user
25
 
26
- # 🔥 IMPORTANT: Expose Hugging Face required port
27
- EXPOSE 7860
28
 
29
- # Start Streamlit on port 7860
30
  CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
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 "7860" 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 CHANGED
@@ -3,66 +3,54 @@ import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
 
6
- # Download the model from the Model Hub
7
- model_path = hf_hub_download(repo_id="Anusha3/ab_predictive_maintenance", filename="Gradient_Boosting.joblib")
 
 
 
8
 
9
- # Load the model
10
  model = joblib.load(model_path)
11
 
12
- # Streamlit UI for Predictive Maintence Prediction
13
  st.set_page_config(page_title="Predictive Maintenance - Engine Failure")
14
- st.title("Aircraft Engine Predictive Maintenance")
15
 
16
- st.write("Enter sensor readings below to predict engine failure probability.")
17
 
18
  # ----------------------------
19
- # Input Features (Based on Engine Dataset)
20
  # ----------------------------
21
 
22
- operational_setting_1 = st.number_input("Operational Setting 1", value=0.0)
23
- operational_setting_2 = st.number_input("Operational Setting 2", value=0.0)
24
- operational_setting_3 = st.number_input("Operational Setting 3", value=0.0)
25
-
26
- sensor_1 = st.number_input("Sensor Measurement 1", value=0.0)
27
- sensor_2 = st.number_input("Sensor Measurement 2", value=0.0)
28
- sensor_3 = st.number_input("Sensor Measurement 3", value=0.0)
29
- sensor_4 = st.number_input("Sensor Measurement 4", value=0.0)
30
- sensor_5 = st.number_input("Sensor Measurement 5", value=0.0)
31
- sensor_6 = st.number_input("Sensor Measurement 6", value=0.0)
32
- sensor_7 = st.number_input("Sensor Measurement 7", value=0.0)
33
- sensor_8 = st.number_input("Sensor Measurement 8", value=0.0)
34
- sensor_9 = st.number_input("Sensor Measurement 9", value=0.0)
35
- sensor_10 = st.number_input("Sensor Measurement 10", value=0.0)
36
 
37
  # ----------------------------
38
  # Prepare Input DataFrame
39
  # ----------------------------
40
 
41
  input_data = pd.DataFrame([{
42
- "operational_setting_1": operational_setting_1,
43
- "operational_setting_2": operational_setting_2,
44
- "operational_setting_3": operational_setting_3,
45
- "sensor_1": sensor_1,
46
- "sensor_2": sensor_2,
47
- "sensor_3": sensor_3,
48
- "sensor_4": sensor_4,
49
- "sensor_5": sensor_5,
50
- "sensor_6": sensor_6,
51
- "sensor_7": sensor_7,
52
- "sensor_8": sensor_8,
53
- "sensor_9": sensor_9,
54
- "sensor_10": sensor_10
55
  }])
56
 
57
  # ----------------------------
58
- # Prediction Section
59
  # ----------------------------
60
 
61
- if st.button("Predict Engine Failure"):
62
 
63
  prediction = model.predict(input_data)[0]
64
 
65
  if prediction == 1:
66
- st.error("🚨 High Risk: Engine Failure Likely. Immediate Maintenance Recommended.")
67
  else:
68
- st.success("✅ Engine Operating Normally. No Immediate Maintenance Required.")
 
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
 
6
+ # Download the model from Hugging Face
7
+ model_path = hf_hub_download(
8
+ repo_id="Anusha3/ab_predictive_maintenance",
9
+ filename="Gradient_Boosting.joblib"
10
+ )
11
 
12
+ # Load model
13
  model = joblib.load(model_path)
14
 
15
+ # Page config
16
  st.set_page_config(page_title="Predictive Maintenance - Engine Failure")
17
+ st.title("Engine Predictive Maintenance System")
18
 
19
+ st.write("Enter engine parameters below to predict engine condition.")
20
 
21
  # ----------------------------
22
+ # Input Features (MATCH TRAINING FEATURES EXACTLY)
23
  # ----------------------------
24
 
25
+ engine_rpm = st.number_input("Engine RPM", value=1500)
26
+ lub_oil_pressure = st.number_input("Lub Oil Pressure", value=3.0)
27
+ fuel_pressure = st.number_input("Fuel Pressure", value=5.0)
28
+ coolant_pressure = st.number_input("Coolant Pressure", value=2.0)
29
+ lub_oil_temp = st.number_input("Lub Oil Temperature", value=80.0)
30
+ coolant_temp = st.number_input("Coolant Temperature", value=75.0)
 
 
 
 
 
 
 
 
31
 
32
  # ----------------------------
33
  # Prepare Input DataFrame
34
  # ----------------------------
35
 
36
  input_data = pd.DataFrame([{
37
+ "Engine rpm": engine_rpm,
38
+ "Lub oil pressure": lub_oil_pressure,
39
+ "Fuel pressure": fuel_pressure,
40
+ "Coolant pressure": coolant_pressure,
41
+ "lub oil temp": lub_oil_temp,
42
+ "Coolant temp": coolant_temp
 
 
 
 
 
 
 
43
  }])
44
 
45
  # ----------------------------
46
+ # Prediction
47
  # ----------------------------
48
 
49
+ if st.button("Predict Engine Condition"):
50
 
51
  prediction = model.predict(input_data)[0]
52
 
53
  if prediction == 1:
54
+ st.error("🚨 Engine Failure Likely. Immediate Maintenance Required!")
55
  else:
56
+ st.success("✅ Engine Operating Normally.")
requirements.txt CHANGED
@@ -1,7 +1,7 @@
1
- huggingface_hub==0.32.6
2
- datasets==3.6.0
3
  pandas==2.2.2
 
 
 
4
  scikit-learn==1.6.0
5
  xgboost==2.1.4
6
- mlflow
7
- streamlit
 
 
 
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==3.0.1