Spaces:
Sleeping
Sleeping
File size: 1,100 Bytes
90776a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import joblib
import os
BACKEND_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
MODEL_PATH = os.path.join(BACKEND_DIR, "ml", "saved_models", "crowd_model.joblib")
COLUMNS_PATH = os.path.join(BACKEND_DIR, "ml", "saved_models", "feature_columns.joblib")
print(f"π Looking for model at: {MODEL_PATH}")
class ModelLoader:
_model = None
_feature_columns = None
@classmethod
def get_model(cls):
if cls._model is None:
print("π Loading ML model...")
if not os.path.exists(MODEL_PATH):
raise FileNotFoundError(
f"β Model not found at {MODEL_PATH}\n"
f"π Run: cd backend/ml && python create_dummy_model.py"
)
cls._model = joblib.load(MODEL_PATH)
print("β
Model loaded successfully!")
return cls._model
@classmethod
def get_feature_columns(cls):
if cls._feature_columns is None:
cls._feature_columns = joblib.load(COLUMNS_PATH)
return cls._feature_columns |