bhumitps commited on
Commit
d0a180b
·
verified ·
1 Parent(s): 61ec17c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -20,9 +20,35 @@ def load_model():
20
  repo_id=MODEL_REPO_ID,
21
  filename=MODEL_FILENAME,
22
  repo_type="model",
23
- force_download=True, # always fetch latest v3 model
24
  )
25
  model = joblib.load(model_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  st.write("Model loaded successfully.")
27
  return model
28
  except Exception as e:
@@ -82,9 +108,7 @@ with col2:
82
  Occupation = st.selectbox(
83
  "Occupation", options=["Salaried", "Self Employed", "Free Lancer", "Other"]
84
  )
85
- Gender = st.selectbox(
86
- "Gender", options=["Male", "Female", "Other"]
87
- )
88
  ProductPitched = st.text_input("ProductPitched (raw value)", value="Basic")
89
  MaritalStatus = st.selectbox(
90
  "MaritalStatus", options=["Married", "Single", "Divorced", "Other"]
 
20
  repo_id=MODEL_REPO_ID,
21
  filename=MODEL_FILENAME,
22
  repo_type="model",
23
+ force_download=True, # always fetch latest v3 model
24
  )
25
  model = joblib.load(model_path)
26
+
27
+ # ------------------------------------------------------------------
28
+ # Patch for xgboost version mismatch:
29
+ # some older models don't have .use_label_encoder,
30
+ # but newer xgboost expects it.
31
+ # ------------------------------------------------------------------
32
+ try:
33
+ from xgboost import XGBClassifier
34
+
35
+ # If it's a sklearn Pipeline, grab the final XGBClassifier
36
+ xgb_clf = None
37
+ if hasattr(model, "named_steps"):
38
+ # our pipeline step is named "model"
39
+ xgb_clf = model.named_steps.get("model", None)
40
+ elif isinstance(model, XGBClassifier):
41
+ xgb_clf = model
42
+
43
+ if isinstance(xgb_clf, XGBClassifier) and not hasattr(
44
+ xgb_clf, "use_label_encoder"
45
+ ):
46
+ # Safe default for modern xgboost
47
+ xgb_clf.use_label_encoder = False
48
+ except Exception:
49
+ # If anything goes wrong with the patch, don't break the app
50
+ pass
51
+
52
  st.write("Model loaded successfully.")
53
  return model
54
  except Exception as e:
 
108
  Occupation = st.selectbox(
109
  "Occupation", options=["Salaried", "Self Employed", "Free Lancer", "Other"]
110
  )
111
+ Gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
 
 
112
  ProductPitched = st.text_input("ProductPitched (raw value)", value="Basic")
113
  MaritalStatus = st.selectbox(
114
  "MaritalStatus", options=["Married", "Single", "Divorced", "Other"]