Perth0603 commited on
Commit
60cd459
·
verified ·
1 Parent(s): 1223c0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -199,19 +199,14 @@ def _load_model():
199
  num_labels = int(getattr(_model.config, "num_labels", 0) or 0)
200
  _NORM_LABELS_BY_IDX = [_normalize_label_text_only(id2label.get(i, f"LABEL_{i}")) for i in range(num_labels)]
201
 
202
- print(f"Model loaded successfully. Labels: {_NORM_LABELS_BY_IDX}")
 
 
203
 
204
 
205
  def _predict_texts(texts: List[str], include_preprocessing: bool = True) -> List[Dict]:
206
  """
207
- Predict and return strictly model-authoritative outputs:
208
- - label: normalized model label (PHISH/LEGIT or other model label uppercased)
209
- - raw_label: original id2label string from model.config
210
- - is_phish: boolean derived from normalized label
211
- - score: probability of predicted class
212
- - probs: dict of normalized label -> probability
213
- - predicted_index: argmax index
214
- - preprocessing: detailed preprocessing steps (if requested)
215
  """
216
  _load_model()
217
  if not texts:
@@ -267,6 +262,8 @@ def _predict_texts(texts: List[str], include_preprocessing: bool = True) -> List
267
  "score": round(float(p[idx].item()), 4),
268
  "probs": {k: round(v, 4) for k, v in prob_map.items()},
269
  "predicted_index": idx,
 
 
270
  }
271
 
272
  # Add preprocessing info if requested
 
199
  num_labels = int(getattr(_model.config, "num_labels", 0) or 0)
200
  _NORM_LABELS_BY_IDX = [_normalize_label_text_only(id2label.get(i, f"LABEL_{i}")) for i in range(num_labels)]
201
 
202
+ print(f"Model loaded successfully. Number of labels: {num_labels}")
203
+ print(f"Label mapping: {id2label}")
204
+ print(f"Normalized labels: {_NORM_LABELS_BY_IDX}")
205
 
206
 
207
  def _predict_texts(texts: List[str], include_preprocessing: bool = True) -> List[Dict]:
208
  """
209
+ Predict and return strictly model-authoritative outputs with enhanced debugging.
 
 
 
 
 
 
 
210
  """
211
  _load_model()
212
  if not texts:
 
262
  "score": round(float(p[idx].item()), 4),
263
  "probs": {k: round(v, 4) for k, v in prob_map.items()},
264
  "predicted_index": idx,
265
+ "all_logits": [round(float(logits[i][j].item()), 4) for j in range(logits.shape[1])], # DEBUG
266
+ "raw_probs": [round(float(p[j].item()), 4) for j in range(len(p))], # DEBUG
267
  }
268
 
269
  # Add preprocessing info if requested