rag / index.html
user
Resolve merge conflicts
e5a2f3a
raw
history blame
2.32 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF RAG Chatbot</title>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
#chat-container { border: 1px solid #ddd; height: 400px; overflow-y: scroll; padding: 10px; margin-bottom: 10px; }
#user-input { width: 70%; padding: 5px; }
#send-button { padding: 5px 10px; }
</style>
</head>
<body>
<h1>PDF RAG Chatbot</h1>
<div id="chat-container"></div>
<input type="text" id="user-input" placeholder="Ask a question...">
<button id="send-button">Send</button>
<script>
const chatContainer = document.getElementById('chat-container');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
function addMessage(role, content) {
const messageDiv = document.createElement('div');
messageDiv.innerHTML = `<strong>${role}:</strong> ${content}`;
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
async function sendMessage() {
const question = userInput.value.trim();
if (question) {
addMessage('User', question);
userInput.value = '';
try {
const response = await fetch('/ask', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ question }),
});
const data = await response.json();
addMessage('Bot', data.response);
} catch (error) {
console.error('Error:', error);
addMessage('Bot', 'Sorry, there was an error processing your request.');
}
}
}
sendButton.addEventListener('click', sendMessage);
userInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') sendMessage();
});
</script>
</body>
</html>