vihu21 commited on
Commit
82ae1aa
·
verified ·
1 Parent(s): 8bcdad0

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +25 -11
  2. app.py +60 -0
  3. requirements.txt +8 -3
Dockerfile CHANGED
@@ -1,20 +1,34 @@
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
+ # Base image
2
+ FROM python:3.9-slim
3
 
4
+ # Environment settings
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+ ENV PYTHONUNBUFFERED=1
7
+
8
+ # Create non-root user
9
+ RUN useradd -m -u 1000 user
10
+
11
+ # Set working directory
12
  WORKDIR /app
13
 
14
+ # Copy dependency file first (better caching)
15
+ COPY requirements.txt .
16
+
17
+ # Install dependencies
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
 
20
+ # Copy application code
21
+ COPY --chown=user . /app
22
 
23
+ # Switch to non-root user
24
+ USER user
25
 
26
+ # Expose Streamlit port
27
  EXPOSE 8501
28
 
29
+ # Streamlit configuration
30
+ ENV STREAMLIT_SERVER_PORT=8501
31
+ ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
32
 
33
+ # Run Streamlit app
34
+ CMD ["streamlit", "run", "engine_predict/deployment/app.py"]
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/adaboost-predictive-maintenance"
10
+ MODEL_FILE = "adaboost_pm.joblib"
11
+
12
+ model_path = hf_hub_download(
13
+ repo_id=HF_MODEL_REPO,
14
+ filename=MODEL_FILE,
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")
requirements.txt CHANGED
@@ -1,3 +1,8 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.4.2
6
+ streamlit==1.43.2
7
+ huggingface_hub==0.29.3
8
+ mlflow