ScamDetect Bot commited on
Commit
3d253e5
·
1 Parent(s): 2e4bf53

Auto-sync backend and fix configuration

Browse files
Files changed (1) hide show
  1. backend/services/scam_detection.py +22 -2
backend/services/scam_detection.py CHANGED
@@ -277,7 +277,9 @@ XAI_VOCAB = {
277
  "urgency": ["urgent", "immediately", "suspend", "block", "freeze", "24 hours", "action required", "turant", "jald", "warn", "last chance", "expire", "band", "block", "freeze"],
278
  "phishing": ["verify", "kyc", "update", "link", "click here", "login", "password", "otp", "pin", "pan card", "adhar", "aadhar", "account", "khata", "password", "verify"],
279
  "financial": ["payment", "transfer", "credited", "debited", "refund", "lottery", "prize", "cash", "rupees", "rs.", "inr", "upi", "paytm", "gpay", "phonepe", "paisa", "paise", "jeet", "lottery", "cashback"],
280
- "threat": ["arrest", "police", "legal action", "fine", "penalty", "warrant", "court", "jail", "fir", "kanoon", "jurmana", "cbi", "tax"]
 
 
281
  }
282
 
283
  def extract_matched_words(text: str, category: str, max_words=3) -> list:
@@ -286,6 +288,18 @@ def extract_matched_words(text: str, category: str, max_words=3) -> list:
286
  matches = [word for word in XAI_VOCAB.get(category, []) if word in text_lower]
287
  return matches[:max_words]
288
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  # --- Adversarial Defense Layer ---
290
  ADVERSARIAL_PATTERNS = [
291
  "ignore previous instructions",
@@ -359,7 +373,13 @@ def analyze_text_with_nlp(text: str):
359
  "Urgency": round(scores_zs.get("urgency", 0) * 100, 1),
360
  "Fear": round(scores_zs.get("threat or blackmail", 0) * 100, 1),
361
  "Authority": round(scores_zs.get("authority impersonation", 0) * 100, 1),
362
- "Reward": round(scores_zs.get("promotional offer", 0) * 100, 1)
 
 
 
 
 
 
363
  }
364
 
365
  # Risk level
 
277
  "urgency": ["urgent", "immediately", "suspend", "block", "freeze", "24 hours", "action required", "turant", "jald", "warn", "last chance", "expire", "band", "block", "freeze"],
278
  "phishing": ["verify", "kyc", "update", "link", "click here", "login", "password", "otp", "pin", "pan card", "adhar", "aadhar", "account", "khata", "password", "verify"],
279
  "financial": ["payment", "transfer", "credited", "debited", "refund", "lottery", "prize", "cash", "rupees", "rs.", "inr", "upi", "paytm", "gpay", "phonepe", "paisa", "paise", "jeet", "lottery", "cashback"],
280
+ "threat": ["arrest", "police", "legal action", "fine", "penalty", "warrant", "court", "jail", "fir", "kanoon", "jurmana", "cbi", "tax"],
281
+ "authority": ["irs", "police", "bank", "manager", "admin", "support", "government", "sbi", "hdfc", "icici", "rbi", "official", "department", "customs", "officer"],
282
+ "reward": ["winner", "congratulations", "won", "prize", "gift", "free", "selected", "claim", "bonus", "reward", "offer", "discount", "lucky", "draw", "iphone", "car"]
283
  }
284
 
285
  def extract_matched_words(text: str, category: str, max_words=3) -> list:
 
288
  matches = [word for word in XAI_VOCAB.get(category, []) if word in text_lower]
289
  return matches[:max_words]
290
 
291
+ def extract_evidence_sentence(text: str, category: str) -> str:
292
+ """Helper to extract the specific sentence containing matched trigger words"""
293
+ words = extract_matched_words(text, category, max_words=10)
294
+ if not words: return ""
295
+ import re
296
+ sentences = re.split(r'(?<=[.!?]) +|\n', text)
297
+ for s in sentences:
298
+ s_lower = s.lower()
299
+ if any(w in s_lower for w in words):
300
+ return s.strip()
301
+ return ""
302
+
303
  # --- Adversarial Defense Layer ---
304
  ADVERSARIAL_PATTERNS = [
305
  "ignore previous instructions",
 
373
  "Urgency": round(scores_zs.get("urgency", 0) * 100, 1),
374
  "Fear": round(scores_zs.get("threat or blackmail", 0) * 100, 1),
375
  "Authority": round(scores_zs.get("authority impersonation", 0) * 100, 1),
376
+ "Reward": round(scores_zs.get("promotional offer", 0) * 100, 1),
377
+ "Evidence": {
378
+ "Urgency": extract_evidence_sentence(text, "urgency"),
379
+ "Fear": extract_evidence_sentence(text, "threat"),
380
+ "Authority": extract_evidence_sentence(text, "authority"),
381
+ "Reward": extract_evidence_sentence(text, "reward")
382
+ }
383
  }
384
 
385
  # Risk level