-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
118 lines (99 loc) · 4.8 KB
/
app.py
File metadata and controls
118 lines (99 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
import requests
# --- Streamlit Page Config ---
st.set_page_config(page_title="PhishGuard AI", layout="wide")
st.markdown("""
<style>
.header { color: #ff4b4b; }
.safe { color: #0f9d58; }
.warning { color: #f4b400; }
.danger { color: #db4437; }
.report-box {
border: 1px solid #ddd;
border-radius: 10px;
padding: 15px;
margin-top: 15px;
background-color: #f9f9f9;
}
</style>
""", unsafe_allow_html=True)
# --- Header ---
st.title("🛡️ PhishGuard AI")
st.markdown("### AI-Powered Phishing Detection System")
# --- Input Mode Selector ---
mode = st.radio("Choose Input Method:", ["Structured Input", "Paste Full Email"])
# --- Mode 1: Structured Input ---
if mode == "Structured Input":
st.subheader("Email Details")
col1, col2 = st.columns(2)
with col1:
subject = st.text_input("Subject", placeholder="e.g., Urgent: Verify your account now!")
with col2:
sender = st.text_input("Sender", placeholder="e.g., security@b4nk-alert.com")
body = st.text_area("Email Body", height=200, placeholder="Paste email content here...")
# Analyze Button
if st.button("Analyze Email"):
if not (subject.strip() and sender.strip() and body.strip()):
st.warning("Please enter complete email details.")
else:
with st.spinner("Detecting phishing indicators..."):
try:
# Send to Agent A endpoint
response = requests.post(
"http://localhost:8000/analyze",
json={"subject": subject, "sender": sender, "body": body}
)
result = response.json()
# Display styled results
st.markdown('<div class="report-box">', unsafe_allow_html=True)
st.markdown("#### **Agent A (Analyzer) Result:**")
st.info(result["analysis"])
st.markdown("#### **Agent B (Verifier) Result:**")
verification_text = result["verification"].lower()
if "phishing" in verification_text:
st.markdown('<p class="danger">🚨 PHISHING CONFIRMED</p>', unsafe_allow_html=True)
st.write(result["verification"])
elif "suspicious" in verification_text:
st.markdown('<p class="warning">⚠️ SUSPICIOUS</p>', unsafe_allow_html=True)
st.write(result["verification"])
else:
st.markdown('<p class="safe">✅ SAFE</p>', unsafe_allow_html=True)
st.write(result["verification"])
st.markdown('</div>', unsafe_allow_html=True)
except Exception as e:
st.error(f"Analysis failed: {str(e)}")
# --- Mode 2: Paste Full Email ---
else:
st.subheader("Paste Full Raw Email")
full_email = st.text_area("Raw Email Content", height=300, placeholder="Paste the full email text (headers + body)...")
# Analyze Button
if st.button("Analyze Raw Email"):
if not full_email.strip():
st.warning("Please paste the full email content.")
else:
with st.spinner("Analyzing full email..."):
try:
# For now, send entire text as 'body' (no subject/sender separation)
response = requests.post(
"http://localhost:8000/analyze",
json={"subject": "Raw Email", "sender": "unknown", "body": full_email}
)
result = response.json()
# Display styled results
st.markdown('<div class="report-box">', unsafe_allow_html=True)
st.markdown("#### **Agent A (Analyzer) Result:**")
st.info(result["analysis"])
st.markdown("#### **Agent B (Verifier) Result:**")
verification_text = result["verification"].lower()
if "phishing" in verification_text:
st.markdown('<p class="danger">🚨 PHISHING CONFIRMED</p>', unsafe_allow_html=True)
st.write(result["verification"])
elif "suspicious" in verification_text:
st.markdown('<p class="warning">⚠️ SUSPICIOUS</p>', unsafe_allow_html=True)
st.write(result["verification"])
else:
st.markdown('<p class="safe">✅ SAFE</p>', unsafe_allow_html=True)
st.write(result["verification"])
st.markdown('</div>', unsafe_allow_html=True)
except Exception as e:
st.error(f"Analysis failed: {str(e)}")