ranimeree commited on
Commit
14ea95a
·
verified ·
1 Parent(s): 6ee6c0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -46
app.py CHANGED
@@ -8,54 +8,18 @@ import os
8
 
9
  print(f"Prediction environment scikit-learn version: {sklearn.__version__}")
10
 
11
- def load_model():
12
- """Load the model with detailed error checking"""
13
- model_path = "model.pkl"
14
-
15
- try:
16
- print(f"Attempting to load model from {os.path.abspath(model_path)}")
17
- if not os.path.exists(model_path):
18
- print(f"Error: Model file not found at {os.path.abspath(model_path)}")
19
- return None
20
-
21
- with open(model_path, 'rb') as f:
22
- try:
23
- model = pickle.load(f)
24
- print("Model loaded successfully, testing prediction...")
25
-
26
- # Test if model can make predictions
27
- dummy_data = pd.DataFrame({
28
- 'num__age': [0],
29
- 'num__avg_glucose_level': [0],
30
- 'num__bmi': [0],
31
- 'cat__gender_Male': [0],
32
- 'cat__gender_Other': [0],
33
- 'cat__hypertension_1': [0],
34
- 'cat__heart_disease_1': [0],
35
- 'cat__ever_married_Yes': [0],
36
- 'cat__work_type_Never_worked': [0],
37
- 'cat__work_type_Private': [0],
38
- 'cat__work_type_Self-employed': [0],
39
- 'cat__work_type_children': [0],
40
- 'cat__Residence_type_Urban': [0],
41
- 'cat__smoking_status_formerly smoked': [0],
42
- 'cat__smoking_status_never smoked': [0],
43
- 'cat__smoking_status_smokes': [0]
44
- })
45
- model.predict_proba(dummy_data)
46
- print("Model testing successful")
47
- return model
48
- except Exception as e:
49
- print(f"Error testing model: {str(e)}")
50
- print(f"Model type: {type(model)}")
51
- print(f"Model attributes: {dir(model)}")
52
- return None
53
- except Exception as e:
54
- print(f"Error loading model file: {str(e)}")
55
- return None
56
 
57
  # Load the model once when starting the app
58
- model = load_model()
 
 
 
 
 
59
 
60
  def preprocess_input(data_dict):
61
  """Preprocess input data to match the training format"""
 
8
 
9
  print(f"Prediction environment scikit-learn version: {sklearn.__version__}")
10
 
11
+ def decode_file(file_path):
12
+ with open(file_path, 'rb') as file:
13
+ obj = pickle.load(file)
14
+ return obj
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Load the model once when starting the app
17
+ try:
18
+ model = decode_file('model.pkl')
19
+ print("Model loaded successfully")
20
+ except Exception as e:
21
+ print(f"Error loading model: {e}")
22
+ model = None
23
 
24
  def preprocess_input(data_dict):
25
  """Preprocess input data to match the training format"""