sellestas commited on
Commit
de9eed5
·
verified ·
1 Parent(s): ab878a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -1,7 +1,15 @@
1
  import streamlit as st
2
- import torch
3
  from transformers import BertTokenizer, BertForSequenceClassification
 
 
 
 
4
 
 
 
 
 
 
5
 
6
  # Sidebar About Us Button
7
  with st.sidebar:
@@ -21,37 +29,21 @@ with st.sidebar:
21
  **Version**: 1.0.0
22
  """)
23
 
24
- # Load model from Hugging Face
25
- MODEL_NAME = "sellestas/scam_slayer_model"
26
- tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
27
- model = BertForSequenceClassification.from_pretrained(MODEL_NAME)
28
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
29
- model.to(device)
30
- model.eval()
31
 
32
- def classify_email(text):
33
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
34
- inputs = {k: v.to(device) for k, v in inputs.items()}
35
- with torch.no_grad():
36
- outputs = model(**inputs)
37
- probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
38
- confidence, prediction = torch.max(probabilities, dim=-1)
39
-
40
- label_map = {0: "Non-Malicious", 1: "Malicious"}
41
- return label_map[prediction.item()], confidence.item() * 100
42
 
43
- # Streamlit UI
44
- st.set_page_config(page_title="Scam Slayer", layout="centered")
45
- st.image("logo.png", width=150)
46
- st.title("🛡️ Scam Slayer - AI Email Threat Detector")
47
- st.markdown("### 🔍 Detect phishing and malicious emails instantly!")
48
-
49
- email_text = st.text_area("✉️ Paste the email content below:", height=200)
50
-
51
- if st.button("Detect Scam", help="Click to analyze the email content"):
52
- if email_text.strip():
53
- category, confidence = classify_email(email_text)
54
- st.success(f"**🔹 Result: {category} ({confidence:.2f}% Confidence)**")
55
- st.markdown("\n ✅ Stay vigilant! 🚀")
56
  else:
57
- st.warning("⚠️ Please enter email content to analyze!")
 
1
  import streamlit as st
 
2
  from transformers import BertTokenizer, BertForSequenceClassification
3
+ import torch
4
+
5
+ # ✅ Move `set_page_config` to the first Streamlit command
6
+ st.set_page_config(page_title="Scam Slayer", layout="centered")
7
 
8
+ # Load Model
9
+ MODEL_NAME = "sellestas/scam_slayer_model"
10
+ tokenizer = BertTokenizer.from_pretrained(MODEL_NAME)
11
+ model = BertForSequenceClassification.from_pretrained(MODEL_NAME)
12
+ model.eval()
13
 
14
  # Sidebar About Us Button
15
  with st.sidebar:
 
29
  **Version**: 1.0.0
30
  """)
31
 
32
+ # UI for email input
33
+ st.title("✉️ Scam Slayer: AI-Powered Email Security")
34
+ st.write("Paste an email below and let AI detect if it's phishing.")
 
 
 
 
35
 
36
+ user_input = st.text_area("📩 Enter email content:", height=200)
 
 
 
 
 
 
 
 
 
37
 
38
+ if st.button("Analyze Email"):
39
+ if user_input.strip():
40
+ inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding="max_length", max_length=128)
41
+ outputs = model(**inputs)
42
+ prediction = torch.argmax(outputs.logits, dim=1).item()
43
+
44
+ categories = {0: "Non-Malicious ✅", 1: "Suspicious ⚠️", 2: "Malicious 🚨"}
45
+ result = categories.get(prediction, "Unknown")
46
+
47
+ st.success(f"🛡️ Scam Slayer Result: **{result}**")
 
 
 
48
  else:
49
+ st.error(" Please enter an email to analyze.")