Project
Project
DOCTYPE html>
<html>
<head>
<title>Cybercrime Chatbot</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f4f4f4;
}
#chat-container {
width: 400px;
border: 1px solid #ccc;
background-color: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
height: 600px;
}
#chat-messages {
flex-grow: 1;
padding: 10px;
overflow-y: auto;
}
.message {
padding: 8px;
margin-bottom: 5px;
border-radius: 5px;
max-width: 80%;
}
.user-message {
background-color: #e0f7fa;
align-self: flex-end;
}
.bot-message {
background-color: #f0f0f0;
align-self: flex-start;
}
#input-container {
display: flex;
padding: 10px;
border-top: 1px solid #ccc;
}
#user-input {
flex-grow: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
#send-button {
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
margin-left: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="chat-container">
<div id="chat-messages"></div>
<div id="input-container">
<input type="text" id="user-input" placeholder="Type your message...">
<button id="send-button">Send</button>
</div>
</div>
<script>
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
let conversationHistory = [];
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}` // If needed
},
body: JSON.stringify({
messages: conversationHistory,
user_input: userMessage
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data.response; // Adjust based on your API's response structure.
} catch (error) {
console.error('Error fetching chatbot response:', error);
return "Sorry, I'm having trouble connecting. Please try again later.";
}
}
sendButton.addEventListener('click', handleUserInput);
userInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
handleUserInput();
}
});
addMessage("Hello! I'm here to help with cybercrime. How can I assist you?",
"bot");
</script>
</body>
</html>