|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>PDF Q&A Chatbot</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<style>
|
|
|
|
html, body {
|
|
height: 100%;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: 'Arial', sans-serif;
|
|
background-image: url('https://source.unsplash.com/1920x1080/?technology,abstract');
|
|
background-size: cover;
|
|
background-position: center;
|
|
}
|
|
|
|
.chat-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.chat-box {
|
|
width: 80%;
|
|
max-width: 800px;
|
|
height: 70vh;
|
|
overflow-y: auto;
|
|
background: rgba(255, 255, 255, 0.9);
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.chat-header {
|
|
text-align: center;
|
|
font-size: 22px;
|
|
font-weight: bold;
|
|
color: #007bff;
|
|
padding-bottom: 10px;
|
|
border-bottom: 2px solid #007bff;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.message-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.user-message, .bot-message {
|
|
margin: 10px 0;
|
|
padding: 12px;
|
|
border-radius: 10px;
|
|
max-width: 80%;
|
|
}
|
|
|
|
.user-message {
|
|
background-color: #007bff;
|
|
color: white;
|
|
align-self: flex-end;
|
|
text-align: right;
|
|
}
|
|
|
|
.bot-message {
|
|
background-color: #f1f1f1;
|
|
align-self: flex-start;
|
|
text-align: left;
|
|
}
|
|
|
|
.image-container img {
|
|
max-width: 100%;
|
|
border-radius: 5px;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.input-group {
|
|
position: fixed;
|
|
bottom: 20px;
|
|
width: 80%;
|
|
max-width: 800px;
|
|
}
|
|
|
|
.form-control {
|
|
height: 50px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.btn {
|
|
height: 50px;
|
|
font-size: 16px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="chat-container">
|
|
<div class="chat-box" id="chat-box">
|
|
<div class="chat-header">π PDF Q&A Chatbot</div>
|
|
<div class="message-container"></div>
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
<input type="text" id="query" class="form-control" placeholder="Ask a question...">
|
|
<button class="btn btn-primary" onclick="fetchAnswer()">Ask</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function fetchAnswer() {
|
|
let query = $("#query").val();
|
|
if (!query) return;
|
|
|
|
let userMessage = `<div class="user-message">π€ ${query}</div>`;
|
|
$("#chat-box .message-container").append(userMessage);
|
|
$("#query").val("");
|
|
|
|
$.ajax({
|
|
url: "/query",
|
|
type: "POST",
|
|
contentType: "application/json",
|
|
data: JSON.stringify({ query: query }),
|
|
success: function(response) {
|
|
let botMessage = `<div class="bot-message">π€ ${response.text || "No answer found."}</div>`;
|
|
$("#chat-box .message-container").append(botMessage);
|
|
|
|
if (response.images) {
|
|
let imageContainer = `<div class="image-container">`;
|
|
response.images.forEach(img => {
|
|
imageContainer += `<img src="${img}" class="img-fluid">`;
|
|
});
|
|
imageContainer += `</div>`;
|
|
$("#chat-box .message-container").append(imageContainer);
|
|
}
|
|
|
|
$("#chat-box").scrollTop($("#chat-box")[0].scrollHeight);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|