Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,38 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 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(
|
| 11 |
model = BertForSequenceClassification.from_pretrained(MODEL_NAME)
|
|
|
|
|
|
|
| 12 |
model.eval()
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
β
**Features**:
|
| 25 |
-
- Detects **Malicious, Suspicious, or Non-Malicious** emails.
|
| 26 |
-
- Uses **NLP** to analyze email content.
|
| 27 |
-
- Provides a **confidence score (1-100%)**.
|
| 28 |
-
|
| 29 |
-
**Version**: 1.0.0
|
| 30 |
-
""")
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
st.
|
| 34 |
-
st.
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
if st.button("
|
| 39 |
-
if
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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.
|
|
|
|
| 1 |
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()}
|
| 16 |
+
with torch.no_grad():
|
| 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!")
|