Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import email
|
| 3 |
+
import email.policy
|
| 4 |
+
|
| 5 |
+
# Define the phishing detection function
|
| 6 |
+
def is_phishing(email_content):
|
| 7 |
+
phishing_keywords = [
|
| 8 |
+
'urgent', 'account verification', 'password reset',
|
| 9 |
+
'login required', 'confirm your identity', 'payment details',
|
| 10 |
+
'verify your account', 'security alert'
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
msg = email.message_from_string(email_content, policy=email.policy.default)
|
| 14 |
+
email_text = msg['subject'] + ' '
|
| 15 |
+
if msg.is_multipart():
|
| 16 |
+
for part in msg.walk():
|
| 17 |
+
content_type = part.get_content_type()
|
| 18 |
+
content_disposition = str(part.get("Content-Disposition"))
|
| 19 |
+
|
| 20 |
+
if content_type == "text/plain" and "attachment" not in content_disposition:
|
| 21 |
+
email_text += part.get_payload(decode=True).decode()
|
| 22 |
+
elif content_type == "text/html" and "attachment" not in content_disposition:
|
| 23 |
+
email_text += part.get_payload(decode=True).decode()
|
| 24 |
+
else:
|
| 25 |
+
email_text += msg.get_payload(decode=True).decode()
|
| 26 |
+
|
| 27 |
+
for keyword in phishing_keywords:
|
| 28 |
+
if keyword in email_text.lower():
|
| 29 |
+
return True
|
| 30 |
+
|
| 31 |
+
return False
|
| 32 |
+
|
| 33 |
+
# Streamlit app layout
|
| 34 |
+
st.title('Phishing Email Detector')
|
| 35 |
+
|
| 36 |
+
# Text area for user input
|
| 37 |
+
user_input = st.text_area("Paste the email content here:", height=300)
|
| 38 |
+
|
| 39 |
+
if st.button('Check Email'):
|
| 40 |
+
if is_phishing(user_input):
|
| 41 |
+
st.error("This email might be a phishing attempt.")
|
| 42 |
+
else:
|
| 43 |
+
st.success("This email seems safe.")
|
| 44 |
+
|