harishsohani commited on
Commit
15ebe59
·
verified ·
1 Parent(s): 3d83c50

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +64 -125
app.py CHANGED
@@ -1,5 +1,3 @@
1
- # import requests for interacting with backend
2
- import requests
3
 
4
  # import streamlit library for IO
5
  import streamlit as st
@@ -7,43 +5,13 @@ import streamlit as st
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
@@ -54,14 +22,15 @@ st.set_page_config(
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
  # ---------------------------------------------------------
@@ -78,69 +47,55 @@ st.write("Fill in the details below and click **Predict** to see if the Engine n
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
 
@@ -156,11 +111,13 @@ if st.button("Check fo Maintenance"):
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-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
166
  json=input_data
@@ -170,34 +127,16 @@ if st.button("Check fo Maintenance"):
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}")
 
 
 
1
 
2
  # import streamlit library for IO
3
  import streamlit as st
 
5
  # import pandas
6
  import pandas as pd
7
 
8
+ # library to download fine from Hugging Face
9
+ from huggingface_hub import hf_hub_download
10
+
11
+ # library to load model
12
+ import joblib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
 
14
 
 
15
 
16
  # ---------------------------------------------------------
17
  # PAGE CONFIG
 
22
  )
23
 
24
 
25
+ # Download and load the model
26
+ model_path = hf_hub_download(
27
+ repo_id="harishsohani/AIMLProjectTest",
28
+ #### Final name will be ####
29
+ # hf_repo_id = "harishsohani/AIMLPredictMaintenance"
30
+ repo_type="space",
31
+ filename="best_eng_fail_pred_model.joblib"
32
+ )
33
+ model = joblib.load(model_path)
34
 
35
 
36
  # ---------------------------------------------------------
 
47
  # ====================================
48
  st.subheader ("Engine Parameters")
49
 
50
+ rpm = st.number_input(
51
+ "Engine RPM (50.0 to 2500.0)",
52
+ min_value=50,
53
+ max_value=2500,
54
+ value=735,
55
+ step=10
 
 
56
  )
57
 
58
+ oil_pressure = st.number_input(
59
+ "Lubricating oil pressure in kilopascals (kPa) (0.001 to 10.0)",
60
+ min_value=0.001,
61
+ max_value=10.0,
62
+ value=3.300,
63
+ step=0.001,
64
+ format="%.3f"
 
 
65
  )
66
 
67
+ fuel_pressure = st.number_input(
68
+ "Fuel Pressure in kilopascals (kPa) (0.01 to 25.0)",
69
+ min_value=0.01,
70
+ max_value=25.0,
71
+ value=6.50,
72
+ step=0.01,
73
+ format="%.2f"
 
 
74
  )
75
 
76
+ coolant_pressure = st.number_input(
77
+ "Coolant Pressure in kilopascals (kPa) (0.01 to 10.0)",
78
+ min_value=0.01,
79
+ max_value=10.0,
80
+ value=2.25,
81
+ step=0.10,
82
+ format="%.2f"
 
 
83
  )
84
 
85
+ lub_oil_temp = st.number_input(
86
+ "Lubricating oil Temperature in degrees Celsius (°C) (50.0 to 100.0)",
87
+ min_value=50.0,
88
+ max_value=100.0,
89
+ value=75.0,
90
+ step=0.1
 
 
 
91
  )
92
 
93
+ coolant_temp = st.number_input(
94
+ "Coolant Temperature in degrees Celsius (°C) (50.0 to 200.0)",
95
+ min_value=50.0,
96
+ max_value=200.0,
97
+ value=75.0,
98
+ step=1.0
 
 
 
99
  )
100
 
101
 
 
111
  'Fuel_pressure' : float(fuel_pressure),
112
  'Coolant_pressure' : float(coolant_pressure),
113
  'lub_oil_temp' : float(lub_oil_temp),
114
+ 'Coolant_temp' : float(lub_oil_temp),
115
  }
116
 
117
  input_df = pd.DataFrame([input_data])
118
 
119
+ prediction = model.predict(input_df)[0]
120
+
121
  response = requests.post (
122
  "https://harishsohani-AIMLProjectTestBackEnd.hf.space/v1/EngPredMaintenance",
123
  json=input_data
 
127
  ## get result as json
128
  result = response.json ()
129
 
130
+ ## Get Sales Prediction Value
131
+ prediction_from_backend = result.get ("NeedsMaintenance") # Extract only the value
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
+ # generate output string
134
+ if prediction_from_backend == 1:
135
+ resultstr = "Engine **likely** needs maintenance."
136
+ else:
137
+ resultstr = "Engine does not need any maintenance"
 
138
 
139
+ st.success(resultstr)
 
140
 
141
  else:
142
  st.error (f"Error processing request- Status Code : {response.status_code}")