Upload pipeline_full.joblib + model.joblib + inference.py
Browse files- README.md +6 -1
- inference.py +11 -11
- model.joblib +2 -2
- pipeline_full.joblib +3 -0
README.md
CHANGED
|
@@ -1 +1,6 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pipeline upload
|
| 2 |
+
This repo contains the saved pipeline and model for the cosmetic category model.
|
| 3 |
+
Files:
|
| 4 |
+
- pipeline_full.joblib
|
| 5 |
+
- model.joblib
|
| 6 |
+
- inference.py
|
inference.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
VECT = joblib.load("vect_f.joblib")\n
|
| 5 |
def run(inputs):
|
| 6 |
try:
|
|
|
|
| 7 |
if isinstance(inputs, dict):
|
| 8 |
if "text" in inputs:
|
| 9 |
X = [inputs["text"]]
|
| 10 |
-
elif "features" in inputs:
|
| 11 |
-
X = [inputs["features"]]
|
| 12 |
else:
|
| 13 |
X = [inputs]
|
| 14 |
else:
|
| 15 |
X = [inputs]
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
except Exception as e:
|
| 21 |
-
return {
|
|
|
|
| 1 |
+
import joblib, numpy as np, os
|
| 2 |
+
MODEL = joblib.load("pipeline_full.joblib") if os.path.exists("pipeline_full.joblib") else joblib.load("model.joblib")
|
| 3 |
+
|
|
|
|
| 4 |
def run(inputs):
|
| 5 |
try:
|
| 6 |
+
# expecting either {"text":"..."} or raw list
|
| 7 |
if isinstance(inputs, dict):
|
| 8 |
if "text" in inputs:
|
| 9 |
X = [inputs["text"]]
|
| 10 |
+
elif "inputs" in inputs and isinstance(inputs["inputs"], dict) and "features" in inputs["inputs"]:
|
| 11 |
+
X = [inputs["inputs"]["features"]]
|
| 12 |
else:
|
| 13 |
X = [inputs]
|
| 14 |
else:
|
| 15 |
X = [inputs]
|
| 16 |
+
if hasattr(MODEL, "predict_proba"):
|
| 17 |
+
return {"prediction": MODEL.predict_proba(X).tolist()}
|
| 18 |
+
else:
|
| 19 |
+
return {"prediction": MODEL.predict(X).tolist()}
|
| 20 |
except Exception as e:
|
| 21 |
+
return {"error": str(e)}
|
model.joblib
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f2f37b0995b3d162b1bd9d7444ae2c49c8ccfae26fc030b75845a597749e7d9
|
| 3 |
+
size 4169433
|
pipeline_full.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f2f37b0995b3d162b1bd9d7444ae2c49c8ccfae26fc030b75845a597749e7d9
|
| 3 |
+
size 4169433
|