Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
-
import matplotlib
|
| 5 |
from transformers import pipeline
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
|
|
|
| 9 |
model = pipeline('text-classification', model="Ajay1311/phish")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def create_speedometer_chart(confidence, is_phishing):
|
|
|
|
| 12 |
fig, ax = plt.subplots(figsize=(6, 3), subplot_kw={'projection': 'polar'})
|
| 13 |
|
| 14 |
confidence_pct = confidence * 100
|
|
@@ -33,6 +70,7 @@ def create_speedometer_chart(confidence, is_phishing):
|
|
| 33 |
return fig
|
| 34 |
|
| 35 |
def analyze_phishing(text):
|
|
|
|
| 36 |
if not text.strip():
|
| 37 |
return "No input provided.", None, "Please enter valid email or URL content for analysis."
|
| 38 |
|
|
@@ -53,9 +91,13 @@ def analyze_phishing(text):
|
|
| 53 |
- Requests for personal credentials
|
| 54 |
- Unusual urgency or threats
|
| 55 |
- Unexpected attachments or links
|
| 56 |
-
|
| 57 |
**Recommendation:** Do not interact with the content until verified by your IT or security team.
|
| 58 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
analysis = f"""
|
| 61 |
✅ **No Threat Detected**
|
|
@@ -66,7 +108,6 @@ def analyze_phishing(text):
|
|
| 66 |
- Avoid clicking unknown links
|
| 67 |
- Be cautious with personal data
|
| 68 |
- Always confirm requests from unknown senders
|
| 69 |
-
|
| 70 |
**Recommendation:** Proceed with standard caution.
|
| 71 |
"""
|
| 72 |
|
|
|
|
| 1 |
+
import smtplib
|
| 2 |
+
from email.mime.text import MIMEText
|
| 3 |
+
from email.mime.multipart import MIMEMultipart
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
import matplotlib.pyplot as plt
|
|
|
|
| 7 |
from transformers import pipeline
|
| 8 |
+
import logging
|
| 9 |
|
| 10 |
+
# Set up logging to log phishing URLs or content
|
| 11 |
+
logging.basicConfig(filename='phishing_urls.log', level=logging.INFO, format='%(asctime)s - %(message)s')
|
| 12 |
|
| 13 |
+
# Initialize Hugging Face model for phishing detection
|
| 14 |
model = pipeline('text-classification', model="Ajay1311/phish")
|
| 15 |
|
| 16 |
+
# Gmail SMTP setup for sending emails
|
| 17 |
+
smtp_server = "smtp.gmail.com"
|
| 18 |
+
smtp_port = 587
|
| 19 |
+
sender_email = "pukumar2003@gmail.com" # Replace with your Gmail address
|
| 20 |
+
sender_password = "qwaw bfdb xdlt qyup" # Replace with your generated App Password
|
| 21 |
+
recipient_email = "report@openphish.com" # Replace with recipient's email (can be your email)
|
| 22 |
+
|
| 23 |
+
def send_email_via_gmail(subject, body):
|
| 24 |
+
"""Function to send email via Gmail SMTP server."""
|
| 25 |
+
try:
|
| 26 |
+
# Create the email content
|
| 27 |
+
message = MIMEMultipart()
|
| 28 |
+
message["From"] = sender_email
|
| 29 |
+
message["To"] = recipient_email
|
| 30 |
+
message["Subject"] = subject
|
| 31 |
+
message.attach(MIMEText(body, "plain"))
|
| 32 |
+
|
| 33 |
+
# Establish connection to Gmail's SMTP server and send the email
|
| 34 |
+
with smtplib.SMTP(smtp_server, smtp_port) as server:
|
| 35 |
+
server.starttls() # Secure connection
|
| 36 |
+
server.login(sender_email, sender_password)
|
| 37 |
+
server.sendmail(sender_email, recipient_email, message.as_string())
|
| 38 |
+
|
| 39 |
+
print("Phishing report email sent successfully!")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Failed to send email: {e}")
|
| 42 |
+
|
| 43 |
+
def log_phishing(url_or_text):
|
| 44 |
+
"""Log phishing URLs or content into a log file."""
|
| 45 |
+
logging.info(f"Phishing detected: {url_or_text}")
|
| 46 |
+
|
| 47 |
def create_speedometer_chart(confidence, is_phishing):
|
| 48 |
+
"""Generate speedometer chart showing confidence of phishing detection."""
|
| 49 |
fig, ax = plt.subplots(figsize=(6, 3), subplot_kw={'projection': 'polar'})
|
| 50 |
|
| 51 |
confidence_pct = confidence * 100
|
|
|
|
| 70 |
return fig
|
| 71 |
|
| 72 |
def analyze_phishing(text):
|
| 73 |
+
"""Function to analyze if text contains phishing content and perform actions accordingly."""
|
| 74 |
if not text.strip():
|
| 75 |
return "No input provided.", None, "Please enter valid email or URL content for analysis."
|
| 76 |
|
|
|
|
| 91 |
- Requests for personal credentials
|
| 92 |
- Unusual urgency or threats
|
| 93 |
- Unexpected attachments or links
|
|
|
|
| 94 |
**Recommendation:** Do not interact with the content until verified by your IT or security team.
|
| 95 |
"""
|
| 96 |
+
|
| 97 |
+
# Send email and log the phishing URL/content
|
| 98 |
+
send_email_via_gmail("Phishing Detected", f"Phishing detected with confidence {score*100:.1f}%: {text}")
|
| 99 |
+
log_phishing(text)
|
| 100 |
+
|
| 101 |
else:
|
| 102 |
analysis = f"""
|
| 103 |
✅ **No Threat Detected**
|
|
|
|
| 108 |
- Avoid clicking unknown links
|
| 109 |
- Be cautious with personal data
|
| 110 |
- Always confirm requests from unknown senders
|
|
|
|
| 111 |
**Recommendation:** Proceed with standard caution.
|
| 112 |
"""
|
| 113 |
|