nansri commited on
Commit
c598b42
·
verified ·
1 Parent(s): e5e51dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -9,18 +9,12 @@ MODEL_REPO_ID = "nansri/engine-predictive-maintenance-model"
9
 
10
  @st.cache_resource
11
  def load_model():
12
- try:
13
- model_path = hf_hub_download(
14
- repo_id=MODEL_REPO_ID,
15
- filename="best_model.joblib",
16
- repo_type="model"
17
- )
18
- return joblib.load(model_path)
19
- except Exception as e:
20
- st.error(f"Model could not be loaded: {e}")
21
- return None
22
-
23
- model = load_model()
24
 
25
  st.title("Predictive Maintenance for Engine Health")
26
  st.write("Enter the engine sensor values below to predict engine condition.")
@@ -33,8 +27,10 @@ lub_oil_temp = st.number_input("Lub Oil Temperature", min_value=0.0, value=78.0)
33
  coolant_temp = st.number_input("Coolant Temperature", min_value=0.0, value=80.5)
34
 
35
  if st.button("Predict Engine Condition"):
36
- if model is not None:
37
- try:
 
 
38
  input_df = pd.DataFrame([{
39
  "Engine_rpm": engine_rpm,
40
  "Lub_oil_pressure": lub_oil_pressure,
@@ -46,13 +42,13 @@ if st.button("Predict Engine Condition"):
46
 
47
  prediction = model.predict(input_df)[0]
48
 
49
- if prediction == 1:
50
- st.error("Prediction: Engine may require maintenance.")
51
- else:
52
- st.success("Prediction: Engine appears to be operating normally.")
53
 
54
- st.write("Input dataframe used for prediction:")
55
- st.dataframe(input_df)
56
 
57
- except Exception as e:
58
- st.error(f"Prediction failed: {e}")
 
9
 
10
  @st.cache_resource
11
  def load_model():
12
+ model_path = hf_hub_download(
13
+ repo_id=MODEL_REPO_ID,
14
+ filename="best_model.joblib",
15
+ repo_type="model"
16
+ )
17
+ return joblib.load(model_path)
 
 
 
 
 
 
18
 
19
  st.title("Predictive Maintenance for Engine Health")
20
  st.write("Enter the engine sensor values below to predict engine condition.")
 
27
  coolant_temp = st.number_input("Coolant Temperature", min_value=0.0, value=80.5)
28
 
29
  if st.button("Predict Engine Condition"):
30
+ try:
31
+ with st.spinner("Loading model and generating prediction..."):
32
+ model = load_model()
33
+
34
  input_df = pd.DataFrame([{
35
  "Engine_rpm": engine_rpm,
36
  "Lub_oil_pressure": lub_oil_pressure,
 
42
 
43
  prediction = model.predict(input_df)[0]
44
 
45
+ if prediction == 1:
46
+ st.error("Prediction: Engine may require maintenance.")
47
+ else:
48
+ st.success("Prediction: Engine appears to be operating normally.")
49
 
50
+ st.write("Input dataframe used for prediction:")
51
+ st.dataframe(input_df)
52
 
53
+ except Exception as e:
54
+ st.error(f"Prediction failed: {e}")