grkavi0912 commited on
Commit
a5372b3
·
verified ·
1 Parent(s): 73de4c7

Update deployment files with latest app.py and requirements.txt

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +98 -0
  3. requirements.txt +7 -3
Dockerfile CHANGED
@@ -1,20 +1,23 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
14
- RUN pip3 install -r requirements.txt
 
 
 
15
 
16
- EXPOSE 8501
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
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 the files from the current directory on the host to the container's /app directory
8
+ COPY . .
 
 
 
9
 
10
+ #Install python dependencies listed in requirements.text
11
+ RUN pip 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 itaccessible externally
23
+ CMD ["streamlit","run","app.py","--server.port=8501", "--server.address=0.0.0.0","--server.enableXsrfProtection=False"]
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import os
5
+
6
+ # Set page config
7
+ st.set_page_config(
8
+ page_title="Engine Condition Predictor",
9
+ page_icon="⚙✨",
10
+ layout="centered",
11
+ initial_sidebar_state="expanded",
12
+ )
13
+
14
+ # --- Paths to model and data ---
15
+ MODEL_PATH = os.path.join(os.path.dirname(__file__), 'engine/model', 'tuned_xgboost_model.pkl')
16
+
17
+ # Create dummy model directory if it doesn't exist (for local testing)
18
+ # In a real deployment, these paths would be correctly set within the Docker container
19
+ # or deployment environment.
20
+ if not os.path.exists(os.path.join(os.path.dirname(__file__), 'engine/model')):
21
+ os.makedirs(os.path.join(os.path.dirname(__file__), 'engine/model'), exist_ok=True)
22
+
23
+ # --- Load the Model ---
24
+ @st.cache_resource
25
+ def load_model(path):
26
+ try:
27
+ model = joblib.load(path)
28
+ return model
29
+ except Exception as e:
30
+ st.error(f"Error loading model: {e}")
31
+ return None
32
+
33
+ model = load_model(MODEL_PATH)
34
+
35
+ # --- Streamlit UI ---
36
+ st.title("\u2699✨ Predictive Engine Maintenance")
37
+ st.markdown("\n")
38
+ st.markdown(
39
+ "This application predicts whether an engine requires maintenance based on its sensor readings."
40
+ )
41
+ st.markdown("\n")
42
+
43
+ st.header("Engine Sensor Data Input")
44
+
45
+ # Input fields for sensor data
46
+ engine_rpm = st.slider("Engine RPM", 0, 2500, 750)
47
+ lub_oil_pressure = st.slider("Lub Oil Pressure (bar/kPa)", 0.0, 10.0, 3.0, 0.1)
48
+ fuel_pressure = st.slider("Fuel Pressure (bar/kPa)", 0.0, 25.0, 7.0, 0.1)
49
+ coolant_pressure = st.slider("Coolant Pressure (bar/kPa)", 0.0, 10.0, 2.5, 0.1)
50
+ lub_oil_temp = st.slider("Lub Oil Temperature (°C)", 60.0, 100.0, 77.0, 0.1)
51
+ coolant_temp = st.slider("Coolant Temperature (°C)", 60.0, 200.0, 78.0, 0.1)
52
+
53
+ # Create a DataFrame for prediction
54
+ input_data = pd.DataFrame(
55
+ [
56
+ {
57
+ "engine_rpm": engine_rpm,
58
+ "lub_oil_pressure": lub_oil_pressure,
59
+ "fuel_pressure": fuel_pressure,
60
+ "coolant_pressure": coolant_pressure,
61
+ "lub_oil_temp": lub_oil_temp,
62
+ "coolant_temp": coolant_temp,
63
+ }
64
+ ]
65
+ )
66
+
67
+ st.markdown("\n")
68
+ if st.button("Predict Engine Condition", help="Click to predict if maintenance is required"):
69
+ if model is not None:
70
+ prediction = model.predict(input_data)[0]
71
+ prediction_proba = model.predict_proba(input_data)[0][1] # Probability of 'Faulty'
72
+
73
+ st.subheader("Prediction Results:")
74
+ if prediction == 1:
75
+ st.error(
76
+ f"**Prediction: Engine requires maintenance!** (
77
+ {prediction_proba:.2f} probability of being faulty)"
78
+ )
79
+ st.markdown(
80
+ "*Proactive intervention is recommended based on sensor readings.*"
81
+ )
82
+ else:
83
+ st.success(
84
+ f"**Prediction: Engine is operating normally.** (
85
+ {prediction_proba:.2f} probability of being faulty)"
86
+ )
87
+ st.markdown(
88
+ "*Continue regular monitoring. No immediate maintenance is indicated.*"
89
+ )
90
+ else:
91
+ st.warning("Model not loaded. Please check the model path and file.")
92
+
93
+ st.sidebar.header("About")
94
+ st.sidebar.info(
95
+ "This application uses a trained XGBoost Classifier model to predict engine "
96
+ "condition. Input sensor data using the sliders to get real-time predictions."
97
+ )
98
+ st.sidebar.caption("Developed by Google Colab AI")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ pandas==2.2.3
2
+ huggingface_hub==0.32.6
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.6.1
6
+ xgboost==2.1.4
7
+ mlflow==3.0.1