cosmetic-category-model / inference.py
ashtii's picture
Upload pipeline_full.joblib + model.joblib + inference.py
248a304
import joblib, numpy as np, os
MODEL = joblib.load("pipeline_full.joblib") if os.path.exists("pipeline_full.joblib") else joblib.load("model.joblib")
def run(inputs):
try:
# expecting either {"text":"..."} or raw list
if isinstance(inputs, dict):
if "text" in inputs:
X = [inputs["text"]]
elif "inputs" in inputs and isinstance(inputs["inputs"], dict) and "features" in inputs["inputs"]:
X = [inputs["inputs"]["features"]]
else:
X = [inputs]
else:
X = [inputs]
if hasattr(MODEL, "predict_proba"):
return {"prediction": MODEL.predict_proba(X).tolist()}
else:
return {"prediction": MODEL.predict(X).tolist()}
except Exception as e:
return {"error": str(e)}