jialitan23 commited on
Commit
ef2d51b
·
verified ·
1 Parent(s): 69cdd68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -17,23 +17,22 @@ numerical_features = ['time_since_last_event']
17
  try:
18
  app_dir = os.path.dirname(os.path.abspath(__file__))
19
 
20
- # Load the model and preprocessing objects
21
  model = joblib.load(os.path.join(app_dir, 'fall_detection_model.joblib'))
22
  scaler = joblib.load(os.path.join(app_dir, 'scaler.joblib'))
23
  encoder = joblib.load(os.path.join(app_dir, 'encoder.joblib'))
24
 
25
- # Get the complete list of column names the model was trained on
26
- encoded_feature_names = encoder.get_feature_names_out(features_to_encode)
27
- all_feature_columns = encoded_feature_names.tolist() + numerical_features
28
 
29
- print("✅ Model and preprocessing tools loaded successfully!")
30
  print("Expected feature columns:", all_feature_columns)
31
 
32
  except FileNotFoundError as e:
33
- print(f"❌ Error: Missing required file. Ensure all model artifacts are in the same directory as app.py. {e}")
34
  except Exception as e:
35
  print(f"❌ Unexpected error during model loading: {e}")
36
 
 
37
  # --- Prediction Function for Gradio ---
38
  def predict_fall(movement_activity, location, day_of_week, time_since_last_event):
39
  if model is None:
 
17
  try:
18
  app_dir = os.path.dirname(os.path.abspath(__file__))
19
 
 
20
  model = joblib.load(os.path.join(app_dir, 'fall_detection_model.joblib'))
21
  scaler = joblib.load(os.path.join(app_dir, 'scaler.joblib'))
22
  encoder = joblib.load(os.path.join(app_dir, 'encoder.joblib'))
23
 
24
+ # Load the exact feature names used during training
25
+ all_feature_columns = joblib.load(os.path.join(app_dir, 'feature_names.joblib'))
 
26
 
27
+ print("✅ Model, encoder, scaler, and feature names loaded successfully!")
28
  print("Expected feature columns:", all_feature_columns)
29
 
30
  except FileNotFoundError as e:
31
+ print(f"❌ Missing required file: {e}")
32
  except Exception as e:
33
  print(f"❌ Unexpected error during model loading: {e}")
34
 
35
+
36
  # --- Prediction Function for Gradio ---
37
  def predict_fall(movement_activity, location, day_of_week, time_since_last_event):
38
  if model is None: