Perth0603 commited on
Commit
6a642c0
·
verified ·
1 Parent(s): f4317f9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -300,11 +300,14 @@ def predict_url(payload: PredictUrlPayload):
300
  "phish_is_positive_env": URL_POSITIVE_CLASS_ENV if URL_POSITIVE_CLASS_ENV else None,
301
  }
302
 
 
 
303
  if isinstance(model_type, str) and model_type == "xgboost_bst":
304
  if xgb is None:
305
  raise RuntimeError("xgboost is not installed but required for this model bundle.")
306
  dmat = xgb.DMatrix(feats)
307
  raw_p_class1 = float(model.predict(dmat)[0]) # P(class == 1)
 
308
  phish_proba = raw_p_class1 if phish_is_positive else (1.0 - raw_p_class1)
309
 
310
  elif hasattr(model, "predict_proba"):
@@ -348,9 +351,13 @@ def predict_url(payload: PredictUrlPayload):
348
  phish_proba = float(phish_proba)
349
  label = "PHISH" if phish_proba >= 0.5 else "LEGIT"
350
  score = phish_proba if label == "PHISH" else (1.0 - phish_proba)
 
 
 
351
 
352
  return {
353
  "label": label,
 
354
  "score": float(score),
355
  "phishing_probability": float(phish_proba),
356
  "backend": str(model_type),
@@ -359,6 +366,7 @@ def predict_url(payload: PredictUrlPayload):
359
  "phish_is_positive": bool(phish_is_positive),
360
  "phish_is_positive_bundle": meta_phish_is_positive,
361
  "phish_is_positive_env": URL_POSITIVE_CLASS_ENV if URL_POSITIVE_CLASS_ENV else None,
 
362
  "feature_cols": feature_cols,
363
  "url_col": url_col,
364
  }
 
300
  "phish_is_positive_env": URL_POSITIVE_CLASS_ENV if URL_POSITIVE_CLASS_ENV else None,
301
  }
302
 
303
+ raw_p_class1_debug: Optional[float] = None
304
+
305
  if isinstance(model_type, str) and model_type == "xgboost_bst":
306
  if xgb is None:
307
  raise RuntimeError("xgboost is not installed but required for this model bundle.")
308
  dmat = xgb.DMatrix(feats)
309
  raw_p_class1 = float(model.predict(dmat)[0]) # P(class == 1)
310
+ raw_p_class1_debug = raw_p_class1
311
  phish_proba = raw_p_class1 if phish_is_positive else (1.0 - raw_p_class1)
312
 
313
  elif hasattr(model, "predict_proba"):
 
351
  phish_proba = float(phish_proba)
352
  label = "PHISH" if phish_proba >= 0.5 else "LEGIT"
353
  score = phish_proba if label == "PHISH" else (1.0 - phish_proba)
354
+ # Map to numeric dataset-style label using resolved polarity
355
+ # If PHISH is the positive (class 1), PHISH -> 1 else 0; if not, invert
356
+ predicted_label_numeric = 1 if ((label == "PHISH") == bool(phish_is_positive)) else 0
357
 
358
  return {
359
  "label": label,
360
+ "predicted_label": int(predicted_label_numeric),
361
  "score": float(score),
362
  "phishing_probability": float(phish_proba),
363
  "backend": str(model_type),
 
366
  "phish_is_positive": bool(phish_is_positive),
367
  "phish_is_positive_bundle": meta_phish_is_positive,
368
  "phish_is_positive_env": URL_POSITIVE_CLASS_ENV if URL_POSITIVE_CLASS_ENV else None,
369
+ "raw_proba_class1": float(raw_p_class1_debug) if raw_p_class1_debug is not None else None,
370
  "feature_cols": feature_cols,
371
  "url_col": url_col,
372
  }