Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 26 |
-
|
| 27 |
-
all_feature_columns = encoded_feature_names.tolist() + numerical_features
|
| 28 |
|
| 29 |
-
print("✅ Model and
|
| 30 |
print("Expected feature columns:", all_feature_columns)
|
| 31 |
|
| 32 |
except FileNotFoundError as e:
|
| 33 |
-
print(f"❌
|
| 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:
|