ashtii commited on
Commit
248a304
·
1 Parent(s): 921112c

Upload pipeline_full.joblib + model.joblib + inference.py

Browse files
Files changed (4) hide show
  1. README.md +6 -1
  2. inference.py +11 -11
  3. model.joblib +2 -2
  4. pipeline_full.joblib +3 -0
README.md CHANGED
@@ -1 +1,6 @@
1
- # Model for cosmetic-category-model\n\nThis folder contains:\n- model.joblib\n- inference.py\n- requirements.txt\n\nInference expects JSON like {"text":"raw product text"} or {"inputs":{"features":[...]}}
 
 
 
 
 
 
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
- # inference.py (auto-generated) - separate vectorizer support
2
- import joblib, numpy as np
3
- MODEL = joblib.load("model.joblib")
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
- # apply TF-IDF vectorizer to incoming text
17
- if isinstance(X[0], str):\n X_trans = VECT.transform(X)\n else:\n # assume already numeric features\n X_trans = X\n
18
- pred = MODEL.predict_proba(X_trans).tolist() if hasattr(MODEL, 'predict_proba') else MODEL.predict(X_trans).tolist()
19
- return { "prediction": pred }
20
  except Exception as e:
21
- return { "error": str(e) }
 
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:01fa97214e2006305b631baeb971a49a69364da975da0d072c05bc77fdb3d72c
3
- size 1784996
 
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