sellestas/ScamSlayerApp
0
1import streamlit as st2import torch3from transformers import BertTokenizer, BertForSequenceClassification4 5# ✅ Ensure set_page_config is the first Streamlit command6st.set_page_config(page_title="Scam Slayer", layout="centered")7 8# Load model from Hugging Face9MODEL_NAME = "sellestas/scam_slayer_model"10 11try: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!")18except Exception as e:19 st.error(f"❌ Error loading model: {e}")20 21# Function to classify email22def 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()}25 with torch.no_grad():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() * 10032 33# UI Layout34st.image("logo.png", width=150)35st.title("🛡️ Scam Slayer - AI Email Threat Detector")36st.markdown("### 🔍 Detect phishing and malicious emails instantly!")37 38# Sidebar About Button39with 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 Input57email_text = st.text_area("✉️ Paste the email content below:", height=200)58 59# Detect Scam Button60if 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!")67 