-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
428 lines (386 loc) · 18.8 KB
/
index.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LLM Paper Finder</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
.paper-card {
transition: all 0.3s ease;
}
.paper-card:hover {
transform: translateY(-5px);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.toggle-button {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-button input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #2196F3;
}
input:checked + .slider:before {
transform: translateX(26px);
}
.category-label {
display: inline-block;
padding: 2px 8px;
border-radius: 12px;
font-size: 0.75rem;
font-weight: 600;
background-color: #e2e8f0;
color: #4a5568;
}
</style>
</head>
<body class="bg-gray-100">
<div class="container mx-auto px-4 py-8">
<div class="flex justify-between items-center mb-8">
<h1 class="text-4xl font-bold text-gray-800">LLM Paper Finder</h1>
<button id="settingsBtn" class="text-2xl text-gray-600 hover:text-gray-800"><i class="fas fa-cog"></i></button>
</div>
<div class="flex items-center justify-end mb-4">
<span class="mr-2">Relevance Mode</span>
<label class="toggle-button">
<input type="checkbox" id="mode-toggle">
<span class="slider"></span>
</label>
<span class="ml-2">Annotation Mode</span>
</div>
<form id="preferences-form" class="mb-8">
<label for="preferences" class="block text-sm font-medium text-gray-700 mb-2">Enter your preferences:</label>
<textarea id="preferences" name="preferences" rows="4" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="e.g., papers on LLM reasoning or scaling laws"></textarea>
<button type="submit" class="mt-4 px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50">Fetch Papers</button>
</form>
<div id="progressBar" class="w-full h-4 bg-gray-200 rounded-full mb-2" style="display: none;">
<div class="h-full bg-blue-500 rounded-full" style="width: 0%"></div>
</div>
<p id="progressText" class="text-sm text-gray-600 mb-4" style="display: none;"></p>
<div id="papers-container" class="space-y-6"></div>
<div class="flex justify-between items-center mt-8">
<button id="prev-page" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-opacity-50">Previous</button>
<span id="page-info" class="text-gray-700"></span>
<button id="next-page" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-opacity-50">Next</button>
</div>
<button id="download-json" class="mt-8 px-4 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50">Download JSON</button>
<button id="view-verdicts" class="mt-4 px-4 py-2 bg-purple-500 text-white rounded-lg hover:bg-purple-600 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-opacity-50">View Verdicts</button>
</div>
<!-- Settings Modal -->
<div id="settingsModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full" style="display: none;">
<div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-1/2 shadow-lg rounded-md bg-white">
<div class="mt-3">
<h2 class="text-2xl font-bold mb-4">Settings</h2>
<form id="settingsForm">
<div class="mb-4">
<label for="openaiKey" class="block text-sm font-medium text-gray-700 mb-2">OpenAI API Key:</label>
<input type="text" id="openaiKey" name="openaiKey" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="Enter your OpenAI API key">
</div>
<div class="mb-4">
<label for="maxResults" class="block text-sm font-medium text-gray-700 mb-2">Max Results:</label>
<input type="number" id="maxResults" name="maxResults" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="Enter max results (e.g., 100)" min="1" max="1000">
</div>
<div class="mb-4">
<label for="papersPerPage" class="block text-sm font-medium text-gray-700 mb-2">Papers Per Page:</label>
<input type="number" id="papersPerPage" name="papersPerPage" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="Enter papers per page (e.g., 10)" min="1" max="100">
</div>
<div class="mb-4">
<label for="dateRange" class="block text-sm font-medium text-gray-700 mb-2">Date Range (days):</label>
<input type="number" id="dateRange" name="dateRange" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="Enter date range in days (e.g., 7)" min="1" max="365">
</div>
<div class="mb-4">
<label for="arxivCategories" class="block text-sm font-medium text-gray-700 mb-2">arXiv Categories:</label>
<input type="text" id="arxivCategories" name="arxivCategories" class="w-full px-3 py-2 text-gray-700 border rounded-lg focus:outline-none focus:border-blue-500" placeholder="Enter arXiv categories (comma-separated, e.g., cs.LG,cs.AI)">
</div>
<button type="submit" class="w-full px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50">Save Settings</button>
</form>
</div>
</div>
</div>
<!-- Verdicts Modal -->
<div id="verdictsModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full" style="display: none;">
<div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-1/2 shadow-lg rounded-md bg-white">
<div class="mt-3 text-center">
<h3 class="text-lg leading-6 font-medium text-gray-900">Verdicts</h3>
<div id="verdictsContainer" class="mt-2 px-7 py-3 text-left">
<!-- Verdicts will be populated here -->
</div>
<div class="items-center px-4 py-3">
<button id="closeVerdictsModal" class="px-4 py-2 bg-gray-500 text-white text-base font-medium rounded-md w-full shadow-sm hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-300">
Close
</button>
</div>
</div>
</div>
</div>
<script>
let currentPage = 1;
let totalPages = 1;
$(document).ready(function() {
$("#preferences-form").submit(function(e) {
e.preventDefault();
fetchPapers();
});
$("#prev-page").click(function() {
if (currentPage > 1) {
currentPage--;
getPage(currentPage);
}
});
$("#next-page").click(function() {
if (currentPage < totalPages) {
currentPage++;
getPage(currentPage);
}
});
$("#download-json").click(function() {
const isAnnotationMode = $("#mode-toggle").is(":checked");
window.location.href = `/download_json?is_annotation_mode=${isAnnotationMode}`;
});
$("#view-verdicts").click(function() {
$.get("/get_verdicts", function(data) {
displayVerdicts(data);
$("#verdictsModal").show();
});
});
$("#closeVerdictsModal").click(function() {
$("#verdictsModal").hide();
});
// Settings modal
const settingsModal = document.getElementById("settingsModal");
const settingsBtn = document.getElementById("settingsBtn");
const settingsSpan = settingsModal.getElementsByClassName("close")[0];
settingsBtn.onclick = function() {
settingsModal.style.display = "block";
}
//settingsSpan.onclick = function() {
// settingsModal.style.display = "none";
//}
window.onclick = function(event) {
if (event.target == settingsModal) {
settingsModal.style.display = "none";
}
if (event.target == document.getElementById("verdictsModal")) {
document.getElementById("verdictsModal").style.display = "none";
}
}
$("#settingsForm").submit(function(e) {
e.preventDefault();
updateSettings();
});
});
function fetchPapers() {
const preferences = $("#preferences").val();
const isAnnotationMode = $("#mode-toggle").is(":checked");
$("#progressBar").show();
$("#progressText").show();
$.ajax({
url: "/fetch_papers",
method: "POST",
data: {
preferences: preferences,
is_annotation_mode: isAnnotationMode
},
xhrFields: {
onprogress: function(e) {
const response = e.currentTarget.response;
const lines = response.split("\n");
const lastLine = lines[lines.length - 2]; // Get the last non-empty line
if (lastLine) {
const data = JSON.parse(lastLine);
if (data.done) {
displayPapers(data.papers);
updatePagination(data.total);
} else {
updateProgress(data.progress, data.current, data.total);
}
}
}
},
success: function(data) {
$("#progressBar").hide();
$("#progressText").hide();
},
error: function(xhr, status, error) {
console.error("Error fetching papers:", error);
$("#progressBar").hide();
$("#progressText").hide();
}
});
}
function updateProgress(progress, current, total) {
$("#progressBar > div").css("width", progress + "%");
$("#progressText").text(`Processing ${current} of ${total} papers`);
}
function displayPapers(papers) {
const container = $("#papers-container");
container.empty();
papers.forEach(function(paper) {
const card = $("<div>").addClass("paper-card bg-white p-6 rounded-lg shadow-md cursor-pointer");
card.append($("<h2>").addClass("text-xl font-semibold mb-2").text(paper.title));
card.append($("<p>").addClass("text-sm text-gray-600 mb-2").text(`Authors: ${paper.authors}`));
card.append($("<p>").addClass("text-sm text-gray-600 mb-2").text(`Published: ${paper.published_date}`));
const categoryLabel = $("<span>").addClass("category-label mb-2").text(paper.primary_category);
card.append(categoryLabel);
const abstractBox = $("<div>").addClass("abstract-box border border-gray-300 rounded p-4 mb-4");
const abstractToggle = $("<div>").addClass("flex justify-between items-center cursor-pointer");
abstractToggle.append($("<span>").addClass("text-blue-500").text("Abstract"));
const toggleIcon = $("<i>").addClass("fas fa-chevron-down text-blue-500");
abstractToggle.append(toggleIcon);
abstractBox.append(abstractToggle);
const abstractContent = $("<p>").addClass("text-sm mt-2 hidden").text(paper.abstract);
abstractBox.append(abstractContent);
abstractToggle.on("click", function(e) {
e.stopPropagation();
abstractContent.toggleClass("hidden");
toggleIcon.toggleClass("fa-chevron-down fa-chevron-up");
});
card.append(abstractBox);
const links = $("<div>").addClass("flex space-x-4 mb-4");
links.append($("<a>").attr("href", paper.pdf_url).attr("target", "_blank").addClass("text-blue-500 hover:underline").text("PDF"));
links.append($("<a>").attr("href", paper.abstract_url).attr("target", "_blank").addClass("text-blue-500 hover:underline").text("arXiv"));
card.append(links);
const voteContainer = $("<div>").addClass("vote-container flex items-center space-x-2");
const upvoteBtn = $("<button>").addClass("text-green-500 hover:text-green-600").html('<i class="fas fa-thumbs-up"></i>');
const downvoteBtn = $("<button>").addClass("text-red-500 hover:text-red-600").html('<i class="fas fa-thumbs-down"></i>');
const voteCount = $("<span>").addClass("text-gray-600").text(paper.votes);
upvoteBtn.click(function(e) {
e.stopPropagation();
vote(paper.arxiv_id, "up", voteCount);
});
downvoteBtn.click(function(e) {
e.stopPropagation();
vote(paper.arxiv_id, "down", voteCount);
});
voteContainer.append(upvoteBtn, downvoteBtn, voteCount);
card.append(voteContainer);
let clickTimer = null;
let clickCount = 0;
card.on("click", function(e) {
if ($(e.target).is('a') || $(e.target).closest('a').length ||
$(e.target).closest('.vote-container').length) {
return; // Don't interfere with links or vote buttons
}
clickCount++;
if (clickCount === 1) {
clickTimer = setTimeout(function() {
vote(paper.arxiv_id, "down", voteCount);
clickCount = 0;
}, 300);
} else if (clickCount === 2) {
clearTimeout(clickTimer);
vote(paper.arxiv_id, "up", voteCount);
clickCount = 0;
}
});
container.append(card);
});
}
function vote(arxivId, voteType, voteCountElement) {
$.ajax({
url: "/vote",
method: "POST",
data: {
arxiv_id: arxivId,
vote_type: voteType
},
success: function(data) {
voteCountElement.text(data.votes);
},
error: function(xhr, status, error) {
console.error("Error voting:", error);
}
});
}
function getPage(page) {
$.get(`/get_page?page=${page}`, function(data) {
displayPapers(data.papers);
updatePagination(data.total);
window.scrollTo(0, 0);
});
}
function updatePagination(total) {
const papersPerPage = 10; // This should match the PAPERS_PER_PAGE value in your Flask app
totalPages = Math.ceil(total / papersPerPage);
$("#page-info").text(`Page ${currentPage} of ${totalPages}`);
$("#prev-page").prop("disabled", currentPage === 1);
$("#next-page").prop("disabled", currentPage === totalPages);
}
function updateSettings() {
const settings = {
openaiKey: $("#openaiKey").val(),
maxResults: $("#maxResults").val(),
papersPerPage: $("#papersPerPage").val(),
dateRange: $("#dateRange").val(),
arxivCategories: $("#arxivCategories").val()
};
$.ajax({
url: "/update_settings",
method: "POST",
data: settings,
success: function(response) {
if (response.success) {
alert("Settings updated successfully!");
document.getElementById("settingsModal").style.display = "none";
} else {
alert("Error updating settings: " + response.message);
}
},
error: function(xhr, status, error) {
console.error("Error updating settings:", error);
alert("Error updating settings. Please try again.");
}
});
}
function displayVerdicts(verdicts) {
const container = $("#verdictsContainer");
container.empty();
if (verdicts.length === 0) {
container.append($("<p>").text("No verdicts available."));
return;
}
verdicts.forEach(function(verdict, index) {
const verdictCard = $("<div>").addClass("bg-white p-4 mb-4 rounded-lg shadow");
verdictCard.append($("<h4>").addClass("text-lg font-semibold mb-2").text(`Verdict ${index + 1}`));
verdictCard.append($("<p>").addClass("mb-1").html(`<strong>Title:</strong> ${verdict.title}`));
verdictCard.append($("<p>").addClass("mb-1").html(`<strong>Verdict:</strong> ${verdict.response}`));
if (verdict.timestamp) {
verdictCard.append($("<p>").addClass("text-sm text-gray-600").text(`Timestamp: ${new Date(verdict.timestamp).toLocaleString()}`));
}
container.append(verdictCard);
});
}
</script>
</body>
</html>