Spaces:
Runtime error
Runtime error
Download model_utils.py from direkKakkar/Docker_MEDSCAN.AI: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/direkKakkar/Docker_MEDSCAN.AI/resolve/main/model_utils.py
- Command line
-
hf download hf://spaces/direkKakkar/Docker_MEDSCAN.AI/model_utils.py
-
curl -L -o model_utils.py https://huggingface.co/spaces/direkKakkar/Docker_MEDSCAN.AI/resolve/main/model_utils.py
1.3 kB
| import os | |
| from pathlib import Path | |
| """ | |
| Risk-level thresholds | |
| Probability scores from `predict_proba` | |
| """ | |
| RISK_THRESHOLDS = { | |
| "critical": 0.85, | |
| "high": 0.65, | |
| "moderate": 0.40 | |
| } | |
| """ | |
| Model file resolution | |
| """ | |
| _BASE_DIR = Path(__file__).parent | |
| _XGBOOST_DIR = _BASE_DIR/"xgboost" | |
| ALLOWED_REPORT_TYPE = {"blood", "lipid", "vitamin_d", "hormone", "kidney", "liver"} | |
| def get_model_path(report_type:str) -> str: | |
| """ | |
| Returns the absolute path to the XGBoost model file(`ml_models/xgboost/model.pkl`) | |
| Priority | |
| -------- | |
| 1. Environment variable XGBOOST_MODEL_PATH | |
| 2. Type specific file ml_models/xgboost/model_{report_type}.pkl | |
| 3. Generic fallback ml_models/xgboost/model.pkl | |
| """ | |
| if report_type not in ALLOWED_REPORT_TYPE: | |
| raise ValueError(f"Invalid report type :{report_type}") | |
| env_path = os.getenv("XGBOOST_MODEL_PATH") | |
| if env_path and os.path.exists(env_path): | |
| return env_path | |
| typed = _XGBOOST_DIR/f"model_{report_type}.pkl" | |
| if typed.exixts(): | |
| return str(typed) | |
| fallback = _XGBOOST_DIR/"model.pkl" | |
| if not fallback.exists(): | |
| raise FileNotFoundError("No model file found for the given report-type") | |
| return str(fallback) | |