Eason918 commited on
Commit
962adf9
·
verified ·
1 Parent(s): f5b0f6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -28,40 +28,44 @@ def extract_urls(text):
28
  return re.findall(url_pattern, text)
29
 
30
  # ---------------- UI START ----------------
31
- st.set_page_config(page_title="📩 Email Malicious Detector", layout="wide")
32
- st.markdown("<h1 style='text-align: center;'>📩 Malicious Email Detection App</h1>", unsafe_allow_html=True)
 
33
 
34
- st.markdown("### ✉️ Enter your email content:")
35
- email_text = st.text_area("Paste your email content here:", height=200)
36
 
37
- if st.button("🚨 Scan Email & Analyze URL"):
38
- if not email_text.strip():
39
- st.warning("⚠️ Please input some email content.")
40
- else:
41
- result1 = pipe1(email_text)[0]
42
- label1, score1 = result1['label'], result1['score']
43
- pred1 = normalize_label(label1)
44
-
45
- if pred1 == "benign":
46
- st.markdown("## 🛡️ **Prediction Result:**")
47
- st.success(f"✅ BENIGN EMAIL CONTENT (Confidence Score: {score1:.2%})")
48
  else:
49
- urls = extract_urls(email_text)
50
- if not urls:
51
- st.warning("⚠️ Email content is malicious, but no URL found for further analysis.")
52
- else:
53
- url = urls[0]
54
- result2 = pipe2(url)[0]
55
- result3 = pipe3(url)[0]
56
- label2, score2 = result2['label'], result2['score']
57
- label3, score3 = result3['label'], result3['score']
58
-
59
- final_label, final_score = calculate_weighted_prediction(label2, score2, label3, score3)
60
 
 
61
  st.markdown("## 🛡️ **Prediction Result:**")
62
- if final_score < 0.6:
63
- st.warning(f"🤔 URLs in email content are UNCERTAIN - Confidence too low ({final_score:.2%}). Please review manually.")
64
- elif final_label == "benign":
65
- st.success(f"✅ URLs in email content are BENIGN (Confidence Score: {final_score:.2%})")
 
66
  else:
67
- st.error(f"⚠️ URLs in email content are MALICIOUS (Confidence Score: {final_score:.2%})")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  return re.findall(url_pattern, text)
29
 
30
  # ---------------- UI START ----------------
31
+ def main():
32
+ st.set_page_config(page_title="📩 Email Malicious Detector", layout="wide")
33
+ st.markdown("<h1 style='text-align: center;'>📩 Malicious Email Detection App</h1>", unsafe_allow_html=True)
34
 
35
+ st.markdown("### ✉️ Enter your email content:")
36
+ email_text = st.text_area("Paste your email content here:", height=200)
37
 
38
+ if st.button("🚨 Scan Email & Analyze URL"):
39
+ if not email_text.strip():
40
+ st.warning("⚠️ Please input some email content.")
 
 
 
 
 
 
 
 
41
  else:
42
+ result1 = pipe1(email_text)[0]
43
+ label1, score1 = result1['label'], result1['score']
44
+ pred1 = normalize_label(label1)
 
 
 
 
 
 
 
 
45
 
46
+ if pred1 == "benign":
47
  st.markdown("## 🛡️ **Prediction Result:**")
48
+ st.success(f"✅ BENIGN EMAIL CONTENT (Confidence Score: {score1:.2%})")
49
+ else:
50
+ urls = extract_urls(email_text)
51
+ if not urls:
52
+ st.warning("⚠️ Email content is malicious, but no URL found for further analysis.")
53
  else:
54
+ url = urls[0]
55
+ result2 = pipe2(url)[0]
56
+ result3 = pipe3(url)[0]
57
+ label2, score2 = result2['label'], result2['score']
58
+ label3, score3 = result3['label'], result3['score']
59
+
60
+ final_label, final_score = calculate_weighted_prediction(label2, score2, label3, score3)
61
+
62
+ st.markdown("## 🛡️ **Prediction Result:**")
63
+ if final_score < 0.6:
64
+ st.warning(f"🤔 URLs in email content are UNCERTAIN - Confidence too low ({final_score:.2%}). Please review manually.")
65
+ elif final_label == "benign":
66
+ st.success(f"✅ URLs in email content are BENIGN (Confidence Score: {final_score:.2%})")
67
+ else:
68
+ st.error(f"⚠️ URLs in email content are MALICIOUS (Confidence Score: {final_score:.2%})")
69
+
70
+ if __name__ == "__main__":
71
+ main()