Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 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 |
-
|
| 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 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 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.
|
|
|
|
| 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.")
|