Download model.py from Asah-ML-Copilot-A25-CS047/Predictive-Machine: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/Asah-ML-Copilot-A25-CS047/Predictive-Machine/resolve/main/model.py
- Command line
-
hf download hf://spaces/Asah-ML-Copilot-A25-CS047/Predictive-Machine/model.py
-
curl -L -o model.py https://huggingface.co/spaces/Asah-ML-Copilot-A25-CS047/Predictive-Machine/resolve/main/model.py
2.26 kB
| import os | |
| import joblib | |
| from keras.models import load_model | |
| class Model: | |
| def __init__(self) -> None: | |
| # Time-Series | |
| self.__model_lstm = os.path.join("model", "model_health_best.keras") | |
| # Anomaly Detection | |
| self.__model_binary = os.path.join("model", "model_binary_smote.pkl") | |
| self.__model_multiclass = os.path.join("model", "model_multi.pkl") | |
| # Scaler Time-Series | |
| self.__scaler_lstm = os.path.join("model", "scaler_lstm.pkl") | |
| # Scaler Anomaly | |
| self.__preprocessor_anomaly = os.path.join("model", "scaler_anomaly.pkl") | |
| self._load_model_and_scalers() | |
| def _load_model_and_scalers(self): | |
| try: | |
| if os.path.exists(self.__model_lstm): | |
| self.model_lstm = load_model(self.__model_lstm) | |
| print("LSTM model loaded successfully") | |
| else: | |
| print(f"⚠ Model not found at {self.__model_lstm}") | |
| if os.path.exists(self.__model_binary): | |
| self.model_binary = joblib.load(self.__model_binary) | |
| print("Binary model loaded successfully") | |
| else: | |
| print(f"⚠ Model not found at {self.__model_binary}") | |
| if os.path.exists(self.__model_multiclass): | |
| self.model_multiclass = joblib.load(self.__model_multiclass) | |
| print("Multiclass model loaded successfully") | |
| else: | |
| print(f"⚠ Model not found at {self.__model_multiclass}") | |
| if os.path.exists(self.__preprocessor_anomaly): | |
| self.preprocessor_anomaly = joblib.load(self.__preprocessor_anomaly) | |
| print("Scaler anomaly model loaded successfully") | |
| else: | |
| print(f"⚠ preprocessor_anomaly not found at {self.__preprocessor_anomaly}") | |
| if os.path.exists(self.__scaler_lstm): | |
| self.scaler_lstm = joblib.load(self.__scaler_lstm) | |
| print("scaler_y loaded successfully") | |
| else: | |
| print(f"⚠ scaler_y not found at {self.__scaler_lstm}") | |
| except Exception as e: | |
| print(f"✗ Error loading model/scalers: {str(e)}") | |