Update templates/index.html
Browse files- templates/index.html +169 -147
templates/index.html
CHANGED
|
@@ -1,147 +1,169 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8"
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1"
|
| 6 |
-
<title>PDF Q&A Chatbot</title>
|
| 7 |
-
<link
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<title>PDF Q&A Chatbot</title>
|
| 7 |
+
<link
|
| 8 |
+
rel="stylesheet"
|
| 9 |
+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
| 10 |
+
/>
|
| 11 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 12 |
+
<style>
|
| 13 |
+
/* Full-Screen Styling */
|
| 14 |
+
html,
|
| 15 |
+
body {
|
| 16 |
+
height: 100%;
|
| 17 |
+
margin: 0;
|
| 18 |
+
padding: 0;
|
| 19 |
+
font-family: "Arial", sans-serif;
|
| 20 |
+
background-image: url("https://source.unsplash.com/1920x1080/?technology,abstract"); /* Change Background */
|
| 21 |
+
background-size: cover;
|
| 22 |
+
background-position: center;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.chat-container {
|
| 26 |
+
display: flex;
|
| 27 |
+
flex-direction: column;
|
| 28 |
+
height: 100vh;
|
| 29 |
+
justify-content: center;
|
| 30 |
+
align-items: center;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.chat-box {
|
| 34 |
+
width: 80%;
|
| 35 |
+
max-width: 800px;
|
| 36 |
+
height: 70vh;
|
| 37 |
+
overflow-y: auto;
|
| 38 |
+
background: rgba(255, 255, 255, 0.9);
|
| 39 |
+
border-radius: 10px;
|
| 40 |
+
padding: 20px;
|
| 41 |
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.chat-header {
|
| 45 |
+
text-align: center;
|
| 46 |
+
font-size: 22px;
|
| 47 |
+
font-weight: bold;
|
| 48 |
+
color: #007bff;
|
| 49 |
+
padding-bottom: 10px;
|
| 50 |
+
border-bottom: 2px solid #007bff;
|
| 51 |
+
margin-bottom: 10px;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.message-container {
|
| 55 |
+
display: flex;
|
| 56 |
+
flex-direction: column;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.user-message,
|
| 60 |
+
.bot-message {
|
| 61 |
+
margin: 10px 0;
|
| 62 |
+
padding: 12px;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
max-width: 80%;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.user-message {
|
| 68 |
+
background-color: #007bff;
|
| 69 |
+
color: white;
|
| 70 |
+
align-self: flex-end;
|
| 71 |
+
text-align: right;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.bot-message {
|
| 75 |
+
background-color: #f1f1f1;
|
| 76 |
+
align-self: flex-start;
|
| 77 |
+
text-align: left;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.image-container img {
|
| 81 |
+
max-width: 100%;
|
| 82 |
+
border-radius: 5px;
|
| 83 |
+
margin-top: 5px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.input-group {
|
| 87 |
+
position: fixed;
|
| 88 |
+
bottom: 20px;
|
| 89 |
+
width: 80%;
|
| 90 |
+
max-width: 800px;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.form-control {
|
| 94 |
+
height: 50px;
|
| 95 |
+
font-size: 16px;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.btn {
|
| 99 |
+
height: 50px;
|
| 100 |
+
font-size: 16px;
|
| 101 |
+
}
|
| 102 |
+
</style>
|
| 103 |
+
</head>
|
| 104 |
+
<body>
|
| 105 |
+
<div class="chat-container">
|
| 106 |
+
<div class="chat-box" id="chat-box">
|
| 107 |
+
<div class="chat-header">📜 PDF Q&A Chatbot</div>
|
| 108 |
+
<div class="message-container"></div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<div class="input-group">
|
| 112 |
+
<input
|
| 113 |
+
type="text"
|
| 114 |
+
id="query"
|
| 115 |
+
class="form-control"
|
| 116 |
+
placeholder="Ask a question..."
|
| 117 |
+
/>
|
| 118 |
+
<button class="btn btn-primary" onclick="fetchAnswer()">Ask</button>
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<script>
|
| 123 |
+
function fetchAnswer() {
|
| 124 |
+
let query = $("#query").val().trim();
|
| 125 |
+
if (!query) return;
|
| 126 |
+
|
| 127 |
+
let userMessage = `<div class="user-message">👤 ${query}</div>`;
|
| 128 |
+
$("#chat-box .message-container").append(userMessage);
|
| 129 |
+
$("#query").val("");
|
| 130 |
+
|
| 131 |
+
$.ajax({
|
| 132 |
+
url: "/query",
|
| 133 |
+
type: "POST",
|
| 134 |
+
contentType: "application/json",
|
| 135 |
+
data: JSON.stringify({ query: query }),
|
| 136 |
+
success: function (response) {
|
| 137 |
+
let botMessage = `<div class="bot-message">🤖 ${
|
| 138 |
+
response.text || "No answer found."
|
| 139 |
+
}</div>`;
|
| 140 |
+
let messageContainer = $("#chat-box .message-container");
|
| 141 |
+
messageContainer.append(botMessage);
|
| 142 |
+
|
| 143 |
+
// Append images if available
|
| 144 |
+
if (response.images && response.images.length > 0) {
|
| 145 |
+
let imageContainer = `<div class="image-container">`;
|
| 146 |
+
response.images.forEach((imgSrc) => {
|
| 147 |
+
imageContainer += `<img src="/${imgSrc}" class="img-fluid">`; // Prepend '/' to make it a valid URL
|
| 148 |
+
});
|
| 149 |
+
imageContainer += `</div>`;
|
| 150 |
+
messageContainer.append(imageContainer);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
// Scroll to bottom
|
| 154 |
+
$("#chat-box").scrollTop($("#chat-box")[0].scrollHeight);
|
| 155 |
+
},
|
| 156 |
+
});
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// Enable 'Enter' key to submit query
|
| 160 |
+
$("#query").keypress(function (event) {
|
| 161 |
+
if (event.which === 13) {
|
| 162 |
+
// 13 is the Enter key
|
| 163 |
+
event.preventDefault(); // Prevent default form submission
|
| 164 |
+
fetchAnswer(); // Trigger the fetch function
|
| 165 |
+
}
|
| 166 |
+
});
|
| 167 |
+
</script>
|
| 168 |
+
</body>
|
| 169 |
+
</html>
|