File size: 4,256 Bytes
d0a6b4f | 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Naive Bayes URL Spam Checker</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f4f4f4;
text-align: center;
padding: 60px;
}
h1 {
color: #2c3e50;
}
input[type="text"] {
width: 60%;
padding: 14px;
font-size: 16px;
border-radius: 8px;
border: 1px solid #ccc;
margin-top: 20px;
}
button {
margin-top: 20px;
padding: 12px 24px;
font-size: 16px;
background-color: #3498db;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
#result {
margin-top: 30px;
font-size: 20px;
font-weight: bold;
}
#reason {
font-size: 16px;
margin-top: 10px;
color: #555;
}
#spellSteps {
margin-top: 20px;
text-align: left;
max-width: 600px;
margin: 20px auto;
background-color: #fff;
padding: 15px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.safe {
color: green;
}
.spam {
color: red;
}
</style>
</head>
<body>
<title>Naive Bayes URL Spam Checker</title>
</head>
<body>
<h1>π Naive Bayes URL Spam Checker</h1>
<input type="text" id="urlInput" placeholder="Enter URL (e.g. http://example.com)">
<br>
<button onclick="checkURL()">Check</button>
<div id="result"></div>
<div id="spellSteps"></div>
<div id="reason"></div>
<script>
async function checkURL() {
const url = document.getElementById("urlInput").value.trim();
const resultDiv = document.getElementById("result");
const reasonDiv = document.getElementById("reason");
const spellStepsDiv = document.getElementById("spellSteps");
resultDiv.innerHTML = "β³ Checking...";
reasonDiv.innerHTML = "";
spellStepsDiv.innerHTML = "";
try {
const response = await fetch('/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: url })
});
const data = await response.json();
if (data.prediction === 1) {
resultDiv.innerHTML = "π« <span class='spam'>SPAM / PHISHING</span>";
} else {
resultDiv.innerHTML = "β
<span class='safe'>This URL is SAFE</span>";
}
if (data.reason) {
reasonDiv.innerText = `π Reason: ${data.reason}`;
}
if (data.steps && data.steps.length > 0) {
const title = document.createElement("h3");
title.innerText = "π§ Spell Checker Log:";
spellStepsDiv.appendChild(title);
data.steps.forEach((step) => {
const line = document.createElement("div");
line.innerHTML = step.valid
? `β
${step.word} β Valid`
: `β ${step.word} β Misspelled`;
line.style.color = step.valid ? "green" : "red";
spellStepsDiv.appendChild(line);
});
}
} catch (err) {
resultDiv.innerHTML = "β οΈ Error checking the URL.";
reasonDiv.innerText = err.message;
}
}
</script>
<div class="mt-6 text-center">
<a href="/naive_bayes" class="inline-block bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded shadow">
β Back to Naive Bayes classification
</a>
</div>
</body>
</html> |