GDMProjects commited on
Commit
efe4b5c
·
verified ·
1 Parent(s): 30a5f7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -5
app.py CHANGED
@@ -1,7 +1,6 @@
1
  # ---------- Host/port ----------
2
  HOST, PORT, SHARE = "0.0.0.0", 7860, True
3
 
4
- # ---------- Env hygiene ----------
5
  import os
6
  os.environ["NO_PROXY"] = "127.0.0.1,localhost,::1"
7
  os.environ["no_proxy"] = "127.0.0.1,localhost,::1"
@@ -10,7 +9,6 @@ for _k in ("HTTP_PROXY","http_proxy","HTTPS_PROXY","https_proxy"):
10
  os.environ.setdefault("GRADIO_OPEN_BROWSER", "false")
11
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
12
 
13
- # --- FORCE NON-INTERACTIVE MATPLOTLIB BACKEND (for SHAP plots) ---
14
  os.environ["MPLBACKEND"] = "Agg"
15
  import matplotlib
16
  matplotlib.use("Agg", force=True)
@@ -118,7 +116,7 @@ def get_global_importance_table(model) -> Optional[pd.DataFrame]:
118
 
119
  return None
120
 
121
- # ---------- Load model (strip .pkl because PyCaret appends) ----------
122
  local_path = hf_hub_download(repo_id=REPO, filename=FNAME, token=TOKEN)
123
  MODEL = load_model(str(Path(local_path).with_suffix("")))
124
 
@@ -190,11 +188,9 @@ def build_sample_choices(df: pd.DataFrame, tgt: str, flt: str = "All") -> List[s
190
  # ---------- SHAP background / explainer ----------
191
  def _prepare_background(df_samples: pd.DataFrame | None, max_rows: int = 200) -> pd.DataFrame:
192
  if df_samples is None or df_samples.empty:
193
- # tiny synthetic background of zeros
194
  bg = pd.DataFrame([{k: 0.0 for k in FEATURES} for _ in range(50)])
195
  else:
196
  bg = df_samples[FEATURES].copy()
197
- # numeric coercion + boolean to {0,1} + median impute
198
  for c in FEATURES:
199
  if c not in bg.columns:
200
  bg[c] = np.nan
 
1
  # ---------- Host/port ----------
2
  HOST, PORT, SHARE = "0.0.0.0", 7860, True
3
 
 
4
  import os
5
  os.environ["NO_PROXY"] = "127.0.0.1,localhost,::1"
6
  os.environ["no_proxy"] = "127.0.0.1,localhost,::1"
 
9
  os.environ.setdefault("GRADIO_OPEN_BROWSER", "false")
10
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
11
 
 
12
  os.environ["MPLBACKEND"] = "Agg"
13
  import matplotlib
14
  matplotlib.use("Agg", force=True)
 
116
 
117
  return None
118
 
119
+ # ---------- Load model ----------
120
  local_path = hf_hub_download(repo_id=REPO, filename=FNAME, token=TOKEN)
121
  MODEL = load_model(str(Path(local_path).with_suffix("")))
122
 
 
188
  # ---------- SHAP background / explainer ----------
189
  def _prepare_background(df_samples: pd.DataFrame | None, max_rows: int = 200) -> pd.DataFrame:
190
  if df_samples is None or df_samples.empty:
 
191
  bg = pd.DataFrame([{k: 0.0 for k in FEATURES} for _ in range(50)])
192
  else:
193
  bg = df_samples[FEATURES].copy()
 
194
  for c in FEATURES:
195
  if c not in bg.columns:
196
  bg[c] = np.nan