Spaces:
Runtime error
Runtime error
Download deployment/predict.py from manoj112025/StreamlitSuperKartMLModel: direct link, hf CLI and curl.
- Browser
- Download file 710 Bytes
-
https://huggingface.co/spaces/manoj112025/StreamlitSuperKartMLModel/resolve/main/deployment/predict.py
- Command line
-
hf download hf://spaces/manoj112025/StreamlitSuperKartMLModel/deployment/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/manoj112025/StreamlitSuperKartMLModel/resolve/main/deployment/predict.py
710 Bytes
| import os | |
| import joblib | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| MODEL_REPO = os.getenv("HF_MODEL_REPO", "manoj112025/SuperKartSalesModel") | |
| MODEL_FILE = "model.joblib" | |
| PREPROCESSOR_FILE = "preprocessor.joblib" | |
| def load_artifacts(): | |
| model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, repo_type="model") | |
| pre_path = hf_hub_download(repo_id=MODEL_REPO, filename=PREPROCESSOR_FILE, repo_type="model") | |
| model = joblib.load(model_path) | |
| preprocessor = joblib.load(pre_path) | |
| return preprocessor, model | |
| def predict_one(df: pd.DataFrame): | |
| preprocessor, model = load_artifacts() | |
| X = preprocessor.transform(df) | |
| y = model.predict(X) | |
| return y | |