Spaces:
Runtime error
Runtime error
Download predict_custom_sample.py from RobbieW0316X/cognitive-decline-detector: direct link, hf CLI and curl.
- Browser
- Download file 798 Bytes
-
https://huggingface.co/spaces/RobbieW0316X/cognitive-decline-detector/resolve/main/predict_custom_sample.py
- Command line
-
hf download hf://spaces/RobbieW0316X/cognitive-decline-detector/predict_custom_sample.py
-
curl -L -o predict_custom_sample.py https://huggingface.co/spaces/RobbieW0316X/cognitive-decline-detector/resolve/main/predict_custom_sample.py
798 Bytes
| import joblib | |
| import pandas as pd | |
| from extract_features import extract_features | |
| # Load the trained model and feature list | |
| model = joblib.load("final_model.pkl") # Make sure it's your trained model | |
| expected_features = joblib.load("expected_features.pkl") # A list of 29 feature names used during training | |
| # Set your test audio file here | |
| file_path = "patient_1_healthy.wav" # or patient_2_cognitive_decline.wav | |
| # Extract features from the file | |
| features = extract_features(file_path) | |
| # Align features to training feature set | |
| X = pd.DataFrame([features]) | |
| X = X.reindex(columns=expected_features, fill_value=0) | |
| # Predict | |
| prediction = model.predict(X)[0] | |
| prob = model.predict_proba(X).max() | |
| print(f"🧠 Predicted Cognitive Status: {prediction} (Confidence: {prob:.2f})") | |