Testys commited on
Commit
5f101d0
·
verified ·
1 Parent(s): 5638701

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -1,21 +1,24 @@
1
  import streamlit as st
2
  import joblib
3
  import numpy as np
 
4
 
5
  # --- 1. Load Model and Define Feature Information ---
6
 
7
  @st.cache_resource
8
  def load_model():
9
  """
10
- Loads the saved model. Using st.cache_resource to load the model only once.
 
11
  """
12
  try:
13
- # Load the pre-trained Voting Classifier model
14
- model = joblib.load('voting_classifier_model.joblib')
 
15
  return model
16
  except FileNotFoundError:
17
- st.error("The model file 'voting_classifier_model.joblib' was not found.")
18
- st.info("Please ensure the model file is in the same directory as this script.")
19
  st.stop()
20
  except Exception as e:
21
  st.error(f"An error occurred while loading the model: {e}")
@@ -23,6 +26,7 @@ def load_model():
23
 
24
  model = load_model()
25
 
 
26
  # --- Hardcoded Feature Information ---
27
  # We define the feature names and their typical ranges (min, mean, max)
28
  # This removes the need to load the original dataset file.
 
1
  import streamlit as st
2
  import joblib
3
  import numpy as np
4
+ import pickle
5
 
6
  # --- 1. Load Model and Define Feature Information ---
7
 
8
  @st.cache_resource
9
  def load_model():
10
  """
11
+ Loads the saved model using pickle.
12
+ Using st.cache_resource to load the model only once.
13
  """
14
  try:
15
+ # Load the pre-trained model from a pickle file
16
+ with open('voting_classifier_model.pkl', 'rb') as f:
17
+ model = pickle.load(f)
18
  return model
19
  except FileNotFoundError:
20
+ st.error("The model file 'voting_classifier_model.pkl' was not found.")
21
+ st.info("Please ensure you have saved your model using pickle and the file is in the same directory.")
22
  st.stop()
23
  except Exception as e:
24
  st.error(f"An error occurred while loading the model: {e}")
 
26
 
27
  model = load_model()
28
 
29
+
30
  # --- Hardcoded Feature Information ---
31
  # We define the feature names and their typical ranges (min, mean, max)
32
  # This removes the need to load the original dataset file.