Spaces:
Runtime error
Runtime error
import streamlit as st | |
import email | |
import email.policy | |
# Define the phishing detection function | |
def is_phishing(email_content): | |
phishing_keywords = [ | |
'urgent', 'account verification', 'password reset', | |
'login required', 'confirm your identity', 'payment details', | |
'verify your account', 'security alert' | |
] | |
msg = email.message_from_string(email_content, policy=email.policy.default) | |
email_text = msg['subject'] + ' ' | |
if msg.is_multipart(): | |
for part in msg.walk(): | |
content_type = part.get_content_type() | |
content_disposition = str(part.get("Content-Disposition")) | |
if content_type == "text/plain" and "attachment" not in content_disposition: | |
email_text += part.get_payload(decode=True).decode() | |
elif content_type == "text/html" and "attachment" not in content_disposition: | |
email_text += part.get_payload(decode=True).decode() | |
else: | |
email_text += msg.get_payload(decode=True).decode() | |
for keyword in phishing_keywords: | |
if keyword in email_text.lower(): | |
return True | |
return False | |
# Streamlit app layout | |
st.title('Phishing Email Detector') | |
# Text area for user input | |
user_input = st.text_area("Paste the email content here:", height=300) | |
if st.button('Check Email'): | |
if is_phishing(user_input): | |
st.error("This email might be a phishing attempt.") | |
else: | |
st.success("This email seems safe.") | |