File size: 710 Bytes
b6ced55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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