driems commited on
Commit
98d0aa3
·
verified ·
1 Parent(s): 1c7019e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a public model for general text classification (no auth required)
5
+ classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
6
+
7
+ def detect_phishing(email_text):
8
+ try:
9
+ result = classifier(email_text[:512])[0]
10
+ label = result["label"]
11
+ score = result["score"]
12
+
13
+ # Simple logic to flag phishing-like emails
14
+ phishing_keywords = ["account", "bank", "verify", "password", "login", "update", "click", "urgent", "confirm"]
15
+ email_lower = email_text.lower()
16
+
17
+ if any(word in email_lower for word in phishing_keywords) or score < 0.6:
18
+ return f"⚠️ Phishing Detected (Confidence: {score:.2f}) — Reason: Suspicious keywords found"
19
+ else:
20
+ return f"✅ Safe Email (Confidence: {score:.2f})"
21
+ except Exception as e:
22
+ return f"❌ Error: {str(e)}"
23
+
24
+ # Gradio Interface
25
+ demo = gr.Interface(
26
+ fn=detect_phishing,
27
+ inputs=gr.Textbox(lines=10, label="Paste Email Content Here"),
28
+ outputs=gr.Textbox(label="Prediction Result"),
29
+ title="🧠 AI-Powered Phishing Email Detector",
30
+ description="Detects phishing emails based on text classification and keyword intelligence."
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch(server_name="0.0.0.0", server_port=7860)