harishsohani commited on
Commit
142ce43
·
verified ·
1 Parent(s): 4ef4cb3

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +15 -12
  2. app.py +207 -0
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 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=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import requests for interacting with backend
2
+ import requests
3
+
4
+ # import streamlit library for IO
5
+ import streamlit as st
6
+
7
+ # import pandas
8
+ import pandas as pd
9
+
10
+ # define functiom which can provide formatted input with appropriate label and input text
11
+ # this will help in p[roducing consistent representation
12
+ def formatted_number_input(title, hint, **kwargs):
13
+ st.markdown(f"**{title}**")
14
+ st.caption(hint)
15
+ return st.number_input("", **kwargs)
16
+
17
+ def formatted_number_input2(title, hint, minval, maxval, defvalue, steps, valformat="%.6f"):
18
+
19
+ st.markdown('<div style="margin-bottom:4px;">', unsafe_allow_html=True)
20
+
21
+ col1, col2 = st.columns([3, 1], vertical_alignment="center")
22
+
23
+ with col1:
24
+ st.markdown(
25
+ f"""
26
+ <div style="line-height:1.0">
27
+ <strong>{title}</strong><br>
28
+ <span style="font-size:1.20em; color:gray;">{hint}</span>
29
+ </div>
30
+ """,
31
+ unsafe_allow_html=True
32
+ )
33
+
34
+ with col2:
35
+ usre_input = st.number_input("",
36
+ min_value=minval,
37
+ max_value=maxval,
38
+ value=defvalue,
39
+ step=steps,
40
+ format=valformat,
41
+ label_visibility="collapsed"
42
+ )
43
+
44
+ st.markdown('</div>', unsafe_allow_html=True)
45
+
46
+ return usre_input
47
+
48
+ # ---------------------------------------------------------
49
+ # PAGE CONFIG
50
+ # ---------------------------------------------------------
51
+ st.set_page_config(
52
+ page_title="Predictive Maintenenace App" #,
53
+ #layout="wide"
54
+ )
55
+
56
+
57
+ st.markdown("""
58
+ <style>
59
+ .block-container {
60
+ padding-top: 0.75rem;
61
+ padding-bottom: 0.75rem;
62
+ }
63
+ </style>
64
+ """, unsafe_allow_html=True)
65
+
66
+
67
+ # ---------------------------------------------------------
68
+ # TITLE
69
+ # ---------------------------------------------------------
70
+ st.title("🏖️ Predict Maintenance")
71
+ st.write("The Predict Maintenance app is a tool to predict if an Engine needs any maintenance based on provided operating sensor parameters.")
72
+ st.write("Fill in the details below and click **Predict** to see if the Engine needs maintenance to prevent from failure.")
73
+
74
+
75
+
76
+ # ====================================
77
+ # Section : Capture Engine Parameters
78
+ # ====================================
79
+ st.subheader ("Engine Parameters")
80
+
81
+ rpm = formatted_number_input2(
82
+ "Lubricating oil pressure in kilopascals (kPa)",
83
+ "50 to 2500",
84
+ minval=50.0,
85
+ maxval=2500.0,
86
+ defvalue=735.0,
87
+ steps=10.0,
88
+ valformat="%.2f"
89
+ )
90
+
91
+
92
+ oil_pressure = formatted_number_input2(
93
+ "Lubricating oil pressure in kilopascals (kPa)",
94
+ "0.001 to 10.0",
95
+ minval=0.001,
96
+ maxval=10.0,
97
+ defvalue=3.300000,
98
+ steps=0.001,
99
+ valformat="%.6f"
100
+ )
101
+
102
+
103
+ fuel_pressure = formatted_number_input2(
104
+ "Fuel Pressure in kilopascals (kPa)",
105
+ "0.01 to 25.0",
106
+ minval=0.01,
107
+ maxval=25.0,
108
+ defvalue=6.500000,
109
+ steps=0.01,
110
+ valformat="%.6f"
111
+ )
112
+
113
+
114
+ coolant_pressure = formatted_number_input2(
115
+ "Coolant Pressure in kilopascals (kPa)",
116
+ "0.01 to 10.0",
117
+ minval=0.01,
118
+ maxval=10.0,
119
+ defvalue=2.250000,
120
+ steps=0.10,
121
+ valformat="%.6f"
122
+ )
123
+
124
+
125
+ lub_oil_temp = formatted_number_input2(
126
+ "Lubricating oil Temperature in degrees Celsius (°C)",
127
+ "50.0 to 100.0",
128
+ minval=50.0,
129
+ maxval=100.0,
130
+ defvalue=75.0,
131
+ steps=0.1,
132
+ valformat="%.6f"
133
+ )
134
+
135
+
136
+ coolant_temp = formatted_number_input2(
137
+ "Coolant Temperature in degrees Celsius (°C)",
138
+ "50.0 to 200.0",
139
+ minval=50.0,
140
+ maxval=200.0,
141
+ defvalue=75.000000,
142
+ steps=0.1,
143
+ valformat="%.6f"
144
+ )
145
+
146
+
147
+ # ==========================
148
+ # Single Value Prediction
149
+ # ==========================
150
+ if st.button("Check fo Maintenance"):
151
+
152
+ # extract the data collected into a structure
153
+ input_data = {
154
+ 'Engine_rpm' : float(rpm),
155
+ 'Lub_oil_pressure' : float(oil_pressure),
156
+ 'Fuel_pressure' : float(fuel_pressure),
157
+ 'Coolant_pressure' : float(coolant_pressure),
158
+ 'lub_oil_temp' : float(lub_oil_temp),
159
+ 'Coolant_temp' : float(coolant_temp),
160
+ }
161
+
162
+ input_df = pd.DataFrame([input_data])
163
+
164
+ response = requests.post (
165
+ "https://harishsohani-AIMLPredictiveMaintenanceBackEnd.hf.space/v1/EngPredMaintenance",
166
+ json=input_data
167
+ )
168
+
169
+ if response.status_code == 200:
170
+ ## get result as json
171
+ result = response.json ()
172
+
173
+ resp_status = result.get ("status")
174
+
175
+ if resp_status == "success":
176
+
177
+ ## Get Sales Prediction Value
178
+ prediction_from_backend = result.get ("prediction") # Extract only the value
179
+
180
+ # generate output string
181
+ if prediction_from_backend == 1:
182
+ resultstr = "Engine **likely** needs maintenance."
183
+ else:
184
+ resultstr = "Engine does not need any maintenance"
185
+
186
+ st.success(resultstr)
187
+
188
+ else:
189
+
190
+ error_str = result.get ("message")
191
+
192
+ st.error(error_str)
193
+
194
+ elif response.status_code == 400 or response.status_code == 500: # known errors
195
+
196
+ ## get result as json
197
+ result = response.json ()
198
+
199
+ error_str = result.get ("message")
200
+ st.error (f"Error processing request- Status Code : {response.status_code}, error : {error_str}")
201
+
202
+ else:
203
+ st.error (f"Error processing request- Status Code : {response.status_code}")
204
+
205
+ # Show the etails of data frame prepared from user input
206
+ st.subheader("📦 Input Data Summary")
207
+ st.dataframe (input_df)