sellestas commited on
Commit
aa203fa
Β·
verified Β·
1 Parent(s): d92f473

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -11
app.py CHANGED
@@ -2,14 +2,23 @@ import streamlit as st
2
  import torch
3
  from transformers import BertTokenizer, BertForSequenceClassification
4
 
 
 
 
5
  # Load model from Hugging Face
6
  MODEL_NAME = "sellestas/scam_slayer_model"
7
- tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
8
- model = BertForSequenceClassification.from_pretrained(MODEL_NAME)
9
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
- model.to(device)
11
- model.eval()
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  def classify_email(text):
14
  inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
15
  inputs = {k: v.to(device) for k, v in inputs.items()}
@@ -17,22 +26,41 @@ def classify_email(text):
17
  outputs = model(**inputs)
18
  probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
19
  confidence, prediction = torch.max(probabilities, dim=-1)
20
-
21
- label_map = {0: "Non-Malicious", 1: "Malicious"}
22
  return label_map[prediction.item()], confidence.item() * 100
23
 
24
- # Streamlit UI
25
- st.set_page_config(page_title="Scam Slayer", layout="centered")
26
  st.image("logo.png", width=150)
27
  st.title("πŸ›‘οΈ Scam Slayer - AI Email Threat Detector")
28
  st.markdown("### πŸ” Detect phishing and malicious emails instantly!")
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  email_text = st.text_area("βœ‰οΈ Paste the email content below:", height=200)
31
 
32
- if st.button("Detect Scam", help="Click to analyze the email content"):
 
33
  if email_text.strip():
34
  category, confidence = classify_email(email_text)
35
  st.success(f"**πŸ”Ή Result: {category} ({confidence:.2f}% Confidence)**")
36
- st.markdown("\n βœ… Stay vigilant! πŸš€")
37
  else:
38
  st.warning("⚠️ Please enter email content to analyze!")
 
2
  import torch
3
  from transformers import BertTokenizer, BertForSequenceClassification
4
 
5
+ # βœ… Ensure set_page_config is the first Streamlit command
6
+ st.set_page_config(page_title="Scam Slayer", layout="centered")
7
+
8
  # Load model from Hugging Face
9
  MODEL_NAME = "sellestas/scam_slayer_model"
 
 
 
 
 
10
 
11
+ try:
12
+ tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
13
+ model = BertForSequenceClassification.from_pretrained(MODEL_NAME)
14
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
+ model.to(device)
16
+ model.eval()
17
+ st.success("βœ… Scam Slayer Model Loaded Successfully!")
18
+ except Exception as e:
19
+ st.error(f"❌ Error loading model: {e}")
20
+
21
+ # Function to classify email
22
  def classify_email(text):
23
  inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
24
  inputs = {k: v.to(device) for k, v in inputs.items()}
 
26
  outputs = model(**inputs)
27
  probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
28
  confidence, prediction = torch.max(probabilities, dim=-1)
29
+
30
+ label_map = {0: "Non-Malicious βœ…", 1: "Malicious 🚨"}
31
  return label_map[prediction.item()], confidence.item() * 100
32
 
33
+ # UI Layout
 
34
  st.image("logo.png", width=150)
35
  st.title("πŸ›‘οΈ Scam Slayer - AI Email Threat Detector")
36
  st.markdown("### πŸ” Detect phishing and malicious emails instantly!")
37
 
38
+ # Sidebar About Button
39
+ with st.sidebar:
40
+ if st.button("ℹ️ About Scam Slayer"):
41
+ st.markdown("""
42
+ ## πŸ“Œ About Scam Slayer
43
+ **AI-powered cybersecurity tool** to detect phishing threats.
44
+
45
+ βœ… **Purpose**: Identify and stop phishing attacks.
46
+ βœ… **Model**: Fine-tuned BERT-based classifier.
47
+ βœ… **Developed for**: **SANS AI Cybersecurity Hackathon 2025**.
48
+ βœ… **Features**:
49
+ - Detects **Malicious & Non-Malicious** emails
50
+ - Uses **NLP** for content analysis
51
+ - Provides a **confidence score** (1-100%)
52
+
53
+ **Version**: 1.0.0
54
+ """)
55
+
56
+ # Email Input
57
  email_text = st.text_area("βœ‰οΈ Paste the email content below:", height=200)
58
 
59
+ # Detect Scam Button
60
+ if st.button("πŸš€ Detect Scam", help="Click to analyze the email content"):
61
  if email_text.strip():
62
  category, confidence = classify_email(email_text)
63
  st.success(f"**πŸ”Ή Result: {category} ({confidence:.2f}% Confidence)**")
64
+ st.markdown("βœ… **Stay vigilant against scams!** πŸš€")
65
  else:
66
  st.warning("⚠️ Please enter email content to analyze!")