Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +128 -85
templates/index.html
CHANGED
|
@@ -14,83 +14,149 @@
|
|
| 14 |
display: flex;
|
| 15 |
align-items: center;
|
| 16 |
justify-content: center;
|
| 17 |
-
padding:
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
width:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
border-radius:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
border-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
animation: typing 3s steps(40, end), blink 0.8s infinite;
|
| 35 |
}
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
background: linear-gradient(
|
| 47 |
-
100deg,
|
| 48 |
-
rgba(255,255,255,0) 20%,
|
| 49 |
-
rgba(255,255,255,0.6) 50%,
|
| 50 |
-
rgba(255,255,255,0) 80%
|
| 51 |
-
);
|
| 52 |
-
background-size: 200% 100%;
|
| 53 |
-
animation: shimmer 1.5s infinite;
|
| 54 |
}
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
</style>
|
| 59 |
</head>
|
| 60 |
|
| 61 |
<body>
|
| 62 |
-
<div class="
|
| 63 |
-
<h1
|
| 64 |
|
| 65 |
<div>
|
| 66 |
-
<label class="block text-lg font-semibold text-gray-700">π Context</label>
|
| 67 |
-
<textarea id="context"
|
| 68 |
-
placeholder="Paste your passage or background information here..."
|
| 69 |
-
class="w-full mt-2 rounded-3xl border border-blue-200 bg-blue-50 p-5 text-gray-800 text-base md:text-lg shadow-inner focus:ring-4 focus:ring-blue-400 min-h-[150px] resize-y transition"></textarea>
|
| 70 |
</div>
|
| 71 |
|
| 72 |
-
<div>
|
| 73 |
-
<label class="block text-lg font-semibold text-gray-700">β Question(s)</label>
|
| 74 |
-
<textarea id="question"
|
| 75 |
-
placeholder="Write one or more questions (each on a new line)..."
|
| 76 |
-
class="w-full mt-2 rounded-3xl border border-indigo-200 bg-indigo-50 p-5 text-gray-800 text-base md:text-lg shadow-inner focus:ring-4 focus:ring-indigo-400 min-h-[120px] resize-y transition"></textarea>
|
| 77 |
</div>
|
| 78 |
|
| 79 |
-
<button id="submit-btn"
|
| 80 |
-
class="w-full py-4 text-lg font-bold text-white rounded-3xl shadow-lg bg-gradient-to-r from-blue-600 via-indigo-500 to-purple-500 hover:scale-[1.03] transition-all duration-300">
|
| 81 |
-
π Ask Question
|
| 82 |
-
</button>
|
| 83 |
|
| 84 |
-
<div>
|
| 85 |
-
<h2
|
| 86 |
-
<div id="answer-box"
|
| 87 |
-
class="bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-200 rounded-3xl p-5 text-gray-900 text-lg min-h-[150px] max-h-[350px] overflow-y-auto shadow-inner">
|
| 88 |
-
</div>
|
| 89 |
</div>
|
| 90 |
|
| 91 |
-
<div>
|
| 92 |
-
<h2
|
| 93 |
-
<ul id="history-list"
|
| 94 |
</div>
|
| 95 |
</div>
|
| 96 |
|
|
@@ -102,64 +168,41 @@
|
|
| 102 |
btn.addEventListener("click", async () => {
|
| 103 |
const context = document.getElementById("context").value.trim();
|
| 104 |
const question = document.getElementById("question").value.trim();
|
| 105 |
-
|
| 106 |
if (!context || !question) {
|
| 107 |
answerBox.textContent = "β οΈ Please provide both context and question(s).";
|
| 108 |
return;
|
| 109 |
}
|
| 110 |
-
|
| 111 |
-
answerBox.innerHTML = `
|
| 112 |
-
<div class="shimmer bg-indigo-100 w-full h-24 rounded-2xl mb-2"></div>
|
| 113 |
-
<div class="shimmer bg-indigo-100 w-11/12 h-24 rounded-2xl"></div>
|
| 114 |
-
`;
|
| 115 |
-
|
| 116 |
try {
|
| 117 |
const res = await fetch("/predict", {
|
| 118 |
method: "POST",
|
| 119 |
headers: { "Content-Type": "application/json" },
|
| 120 |
body: JSON.stringify({ context, question })
|
| 121 |
});
|
| 122 |
-
|
| 123 |
const data = await res.json();
|
| 124 |
if (data.error) {
|
| 125 |
answerBox.textContent = "β οΈ " + data.error;
|
| 126 |
return;
|
| 127 |
}
|
| 128 |
-
|
| 129 |
answerBox.innerHTML = "";
|
| 130 |
-
|
| 131 |
-
const r = data.results[i];
|
| 132 |
const qaDiv = document.createElement("div");
|
| 133 |
-
qaDiv.className = "mb-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
const aElem = document.createElement("p");
|
| 140 |
-
aElem.className = "text-gray-900 typing";
|
| 141 |
-
aElem.innerHTML = `<strong>Answer:</strong> ${r.answer}`;
|
| 142 |
-
|
| 143 |
-
const sElem = document.createElement("p");
|
| 144 |
-
sElem.innerHTML = `<strong>Confidence:</strong> ${r.score}`;
|
| 145 |
-
sElem.className = "text-gray-700 text-sm";
|
| 146 |
-
|
| 147 |
-
qaDiv.appendChild(qElem);
|
| 148 |
-
qaDiv.appendChild(aElem);
|
| 149 |
-
qaDiv.appendChild(sElem);
|
| 150 |
-
|
| 151 |
answerBox.appendChild(qaDiv);
|
| 152 |
-
}
|
| 153 |
|
| 154 |
const li = document.createElement("li");
|
| 155 |
li.textContent = question.replace(/\n/g, " | ");
|
| 156 |
-
li.className = "bg-gradient-to-r from-indigo-100 to-purple-100 px-4 py-3 rounded-xl shadow cursor-pointer hover:scale-[1.02] transition";
|
| 157 |
li.addEventListener("click", () => {
|
| 158 |
document.getElementById("question").value = question;
|
| 159 |
document.getElementById("question").scrollIntoView({ behavior: "smooth" });
|
| 160 |
});
|
| 161 |
historyList.prepend(li);
|
| 162 |
-
|
| 163 |
} catch (err) {
|
| 164 |
answerBox.textContent = "β Error: Unable to get response from server.";
|
| 165 |
}
|
|
|
|
| 14 |
display: flex;
|
| 15 |
align-items: center;
|
| 16 |
justify-content: center;
|
| 17 |
+
padding: 2rem;
|
| 18 |
}
|
| 19 |
|
| 20 |
+
.container {
|
| 21 |
+
width: 90%;
|
| 22 |
+
max-width: 900px;
|
| 23 |
+
background: rgba(255, 255, 255, 0.95);
|
| 24 |
+
border-radius: 40px;
|
| 25 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
| 26 |
+
padding: 2.5rem;
|
| 27 |
+
backdrop-filter: blur(12px);
|
| 28 |
+
border: 1px solid rgba(147, 197, 253, 0.3);
|
| 29 |
}
|
| 30 |
+
|
| 31 |
+
textarea {
|
| 32 |
+
border-radius: 30px;
|
| 33 |
+
border: 1px solid #c7d2fe;
|
| 34 |
+
background-color: #eef2ff;
|
| 35 |
+
padding: 1.25rem 1.5rem;
|
| 36 |
+
font-size: 1.15rem;
|
| 37 |
+
color: #1e293b;
|
| 38 |
+
width: 100%;
|
| 39 |
+
min-height: 180px;
|
| 40 |
+
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.05);
|
| 41 |
+
resize: vertical;
|
| 42 |
+
transition: all 0.25s ease;
|
| 43 |
}
|
| 44 |
|
| 45 |
+
textarea:focus {
|
| 46 |
+
outline: none;
|
| 47 |
+
border-color: #6366f1;
|
| 48 |
+
background-color: #e0e7ff;
|
| 49 |
+
box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
|
|
|
|
| 50 |
}
|
| 51 |
+
|
| 52 |
+
button {
|
| 53 |
+
font-weight: 700;
|
| 54 |
+
border: none;
|
| 55 |
+
border-radius: 30px;
|
| 56 |
+
background: linear-gradient(90deg, #2563eb, #7c3aed, #9333ea);
|
| 57 |
+
color: white;
|
| 58 |
+
padding: 1.25rem;
|
| 59 |
+
width: 100%;
|
| 60 |
+
font-size: 1.25rem;
|
| 61 |
+
letter-spacing: 0.5px;
|
| 62 |
+
box-shadow: 0 5px 15px rgba(99, 102, 241, 0.3);
|
| 63 |
+
transition: all 0.3s ease;
|
| 64 |
}
|
| 65 |
+
|
| 66 |
+
button:hover {
|
| 67 |
+
transform: scale(1.03);
|
| 68 |
+
background: linear-gradient(90deg, #3b82f6, #8b5cf6, #a855f7);
|
| 69 |
+
box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
#answer-box {
|
| 73 |
+
background: linear-gradient(to bottom right, #eef2ff, #e0f2fe);
|
| 74 |
+
border: 1px solid #c7d2fe;
|
| 75 |
+
border-radius: 30px;
|
| 76 |
+
padding: 1.5rem;
|
| 77 |
+
font-size: 1.1rem;
|
| 78 |
+
color: #1e293b;
|
| 79 |
+
max-height: 500px;
|
| 80 |
+
overflow-y: auto;
|
| 81 |
+
box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.05);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
#history-list {
|
| 85 |
+
max-height: 250px;
|
| 86 |
+
overflow-y: auto;
|
| 87 |
+
font-size: 1.05rem;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
#history-list li {
|
| 91 |
+
background: linear-gradient(to right, #e0e7ff, #f3e8ff);
|
| 92 |
+
padding: 1rem 1.25rem;
|
| 93 |
+
border-radius: 20px;
|
| 94 |
+
cursor: pointer;
|
| 95 |
+
transition: all 0.25s ease;
|
| 96 |
+
font-weight: 500;
|
| 97 |
}
|
| 98 |
|
| 99 |
+
#history-list li:hover {
|
| 100 |
+
transform: scale(1.03);
|
| 101 |
+
background: linear-gradient(to right, #c7d2fe, #ddd6fe);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
+
|
| 104 |
+
h1 {
|
| 105 |
+
font-size: 2.8rem;
|
| 106 |
+
text-align: center;
|
| 107 |
+
color: #4f46e5;
|
| 108 |
+
font-weight: 800;
|
| 109 |
+
margin-bottom: 1.5rem;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
h2 {
|
| 113 |
+
font-size: 1.8rem;
|
| 114 |
+
font-weight: 700;
|
| 115 |
+
color: #4338ca;
|
| 116 |
+
margin-bottom: 1rem;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
@media (max-width: 640px) {
|
| 120 |
+
.container {
|
| 121 |
+
padding: 1.5rem;
|
| 122 |
+
}
|
| 123 |
+
textarea, button {
|
| 124 |
+
font-size: 1.05rem;
|
| 125 |
+
}
|
| 126 |
+
h1 {
|
| 127 |
+
font-size: 2rem;
|
| 128 |
+
}
|
| 129 |
+
h2 {
|
| 130 |
+
font-size: 1.4rem;
|
| 131 |
+
}
|
| 132 |
}
|
| 133 |
</style>
|
| 134 |
</head>
|
| 135 |
|
| 136 |
<body>
|
| 137 |
+
<div class="container">
|
| 138 |
+
<h1>π¬ Ask Your Doubts</h1>
|
| 139 |
|
| 140 |
<div>
|
| 141 |
+
<label class="block text-lg font-semibold text-gray-700 mb-2">π Context</label>
|
| 142 |
+
<textarea id="context" placeholder="Paste your passage or background information here..."></textarea>
|
|
|
|
|
|
|
| 143 |
</div>
|
| 144 |
|
| 145 |
+
<div class="mt-6">
|
| 146 |
+
<label class="block text-lg font-semibold text-gray-700 mb-2">β Question(s)</label>
|
| 147 |
+
<textarea id="question" placeholder="Write one or more questions (each on a new line)..."></textarea>
|
|
|
|
|
|
|
| 148 |
</div>
|
| 149 |
|
| 150 |
+
<button id="submit-btn" class="mt-8">π Ask Question</button>
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
<div class="mt-8">
|
| 153 |
+
<h2>π‘ Answers</h2>
|
| 154 |
+
<div id="answer-box"></div>
|
|
|
|
|
|
|
| 155 |
</div>
|
| 156 |
|
| 157 |
+
<div class="mt-8">
|
| 158 |
+
<h2>π History</h2>
|
| 159 |
+
<ul id="history-list"></ul>
|
| 160 |
</div>
|
| 161 |
</div>
|
| 162 |
|
|
|
|
| 168 |
btn.addEventListener("click", async () => {
|
| 169 |
const context = document.getElementById("context").value.trim();
|
| 170 |
const question = document.getElementById("question").value.trim();
|
|
|
|
| 171 |
if (!context || !question) {
|
| 172 |
answerBox.textContent = "β οΈ Please provide both context and question(s).";
|
| 173 |
return;
|
| 174 |
}
|
| 175 |
+
answerBox.innerHTML = "<p class='text-indigo-500 font-semibold'>β³ Fetching answer...</p>";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
try {
|
| 177 |
const res = await fetch("/predict", {
|
| 178 |
method: "POST",
|
| 179 |
headers: { "Content-Type": "application/json" },
|
| 180 |
body: JSON.stringify({ context, question })
|
| 181 |
});
|
|
|
|
| 182 |
const data = await res.json();
|
| 183 |
if (data.error) {
|
| 184 |
answerBox.textContent = "β οΈ " + data.error;
|
| 185 |
return;
|
| 186 |
}
|
|
|
|
| 187 |
answerBox.innerHTML = "";
|
| 188 |
+
data.results.forEach((r, i) => {
|
|
|
|
| 189 |
const qaDiv = document.createElement("div");
|
| 190 |
+
qaDiv.className = "mb-5 p-5 bg-gradient-to-br from-indigo-100 to-blue-100 rounded-2xl shadow";
|
| 191 |
+
qaDiv.innerHTML = `
|
| 192 |
+
<p class="font-semibold text-blue-800 text-lg"><strong>Q${i + 1}:</strong> ${r.question}</p>
|
| 193 |
+
<p class="mt-2 text-gray-900 text-base"><strong>Answer:</strong> ${r.answer}</p>
|
| 194 |
+
<p class="text-sm text-gray-600 mt-1"><strong>Confidence:</strong> ${r.score}</p>
|
| 195 |
+
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
answerBox.appendChild(qaDiv);
|
| 197 |
+
});
|
| 198 |
|
| 199 |
const li = document.createElement("li");
|
| 200 |
li.textContent = question.replace(/\n/g, " | ");
|
|
|
|
| 201 |
li.addEventListener("click", () => {
|
| 202 |
document.getElementById("question").value = question;
|
| 203 |
document.getElementById("question").scrollIntoView({ behavior: "smooth" });
|
| 204 |
});
|
| 205 |
historyList.prepend(li);
|
|
|
|
| 206 |
} catch (err) {
|
| 207 |
answerBox.textContent = "β Error: Unable to get response from server.";
|
| 208 |
}
|