File size: 4,508 Bytes
ae0d857 |
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 |
<!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/[email protected]/dist/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
/* Full-Screen Styling */
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: "Arial", sans-serif;
background-image: url("https://source.unsplash.com/1920x1080/?technology,abstract"); /* Change Background */
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().trim();
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>`;
let messageContainer = $("#chat-box .message-container");
messageContainer.append(botMessage);
// Append images if available
if (response.images && response.images.length > 0) {
let imageContainer = `<div class="image-container">`;
response.images.forEach((imgSrc) => {
imageContainer += `<img src="/${imgSrc}" class="img-fluid">`; // Prepend '/' to make it a valid URL
});
imageContainer += `</div>`;
messageContainer.append(imageContainer);
}
// Scroll to bottom
$("#chat-box").scrollTop($("#chat-box")[0].scrollHeight);
},
});
}
// Enable 'Enter' key to submit query
$("#query").keypress(function (event) {
if (event.which === 13) {
// 13 is the Enter key
event.preventDefault(); // Prevent default form submission
fetchAnswer(); // Trigger the fetch function
}
});
</script>
</body>
</html>
|