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