File size: 4,442 Bytes
55ee048 |
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fraud Detection Chatbot</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 0;
padding: 0;
background: #f1f2f7;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
h2 {
margin: 20px;
color: #333;
}
#chat-box {
width: 90%;
max-width: 600px;
background: white;
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
overflow: hidden;
flex-grow: 1;
}
#messages {
flex: 1;
overflow-y: auto;
padding: 20px;
}
.msg {
margin-bottom: 10px;
padding: 10px 14px;
border-radius: 20px;
max-width: 80%;
word-wrap: break-word;
line-height: 1.4;
}
.bot {
background-color: #e9ecef;
align-self: flex-start;
color: #333;
}
.user {
background-color: #0d6efd;
color: white;
align-self: flex-end;
}
#input-bar {
display: flex;
padding: 10px;
border-top: 1px solid #ddd;
background: #f9f9f9;
}
#input {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 20px;
outline: none;
margin-right: 10px;
}
#send-btn, #upload-btn {
background-color: #0d6efd;
color: white;
border: none;
padding: 10px 14px;
border-radius: 20px;
cursor: pointer;
}
#fileInput {
margin: 10px 0;
}
@media (max-width: 600px) {
#chat-box {
width: 95%;
}
}
</style>
</head>
<body>
<h2>π¬ Fraud Detection Chatbot</h2>
<div id="chat-box">
<div id="messages"></div>
<div style="padding: 10px; text-align: center;">
<input type="file" id="fileInput">
<button id="upload-btn" onclick="uploadFile()">Upload CSV</button>
</div>
<div id="input-bar">
<input id="input" type="text" placeholder="Type your message...">
<button id="send-btn" onclick="sendMessage()">Send</button>
</div>
</div>
<script>
const messages = document.getElementById("messages");
function addMessage(text, sender) {
const msg = document.createElement("div");
msg.className = `msg ${sender}`;
msg.textContent = text;
messages.appendChild(msg);
messages.scrollTop = messages.scrollHeight;
}
async function sendMessage() {
const input = document.getElementById("input");
const text = input.value.trim();
if (!text) return;
addMessage(text, "user");
input.value = "";
const res = await fetch("http://127.0.0.1:8000/chat/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: text })
});
const data = await res.json();
addMessage(data.response, "bot");
}
async function uploadFile() {
const file = document.getElementById("fileInput").files[0];
if (!file) {
alert("Please select a CSV file first.");
return;
}
const formData = new FormData();
formData.append("file", file);
addMessage("π Analyzing your file...", "bot");
const res = await fetch("http://127.0.0.1:8000/upload/", {
method: "POST",
body: formData
});
const data = await res.json();
addMessage(data.response, "bot");
}
async function uploadFile() {
const file = document.getElementById("fileInput").files[0];
if (!file) {
alert("Please select a CSV file first.");
return;
}
const formData = new FormData();
formData.append("file", file);
addMessage("π Analyzing your file...", "bot");
try {
const res = await fetch("http://127.0.0.1:8000/upload/", {
method: "POST",
body: formData
});
if (!res.ok) {
throw new Error(`Server error: ${res.status}`);
}
const data = await res.json();
addMessage(data.response || "No response from server.", "bot");
} catch (err) {
addMessage(`β Error: ${err.message}`, "bot");
}
}
</script>
</body>
</html>
|