iThors commited on
Commit
cfb6146
·
verified ·
1 Parent(s): 599bc5c

Update frontend/index.html

Browse files
Files changed (1) hide show
  1. frontend/index.html +61 -163
frontend/index.html CHANGED
@@ -16,6 +16,31 @@
16
  color: #333;
17
  min-height: 100vh;
18
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  h1 {
20
  font-size: 2.5rem;
21
  margin-top: 2rem;
@@ -25,6 +50,7 @@
25
  font-size: 1.2rem;
26
  margin-bottom: 2rem;
27
  color: white;
 
28
  }
29
  .upload-box {
30
  background: #f7f7f7;
@@ -34,10 +60,6 @@
34
  width: 350px;
35
  text-align: center;
36
  }
37
- input[type="file"], input[type="number"], input[type="range"] {
38
- margin: 0.5rem 0;
39
- width: 100%;
40
- }
41
  .slider-container {
42
  margin: 1rem 0;
43
  text-align: left;
@@ -58,119 +80,58 @@
58
  button:hover {
59
  background: #3b8fe0;
60
  }
61
- .progress-bar {
62
- height: 10px;
63
- background: #ddd;
64
- border-radius: 5px;
65
- overflow: hidden;
66
- margin: 1rem 0;
67
- display: none;
68
- }
69
- .progress-bar-inner {
70
- height: 100%;
71
- width: 0%;
72
- background: #4facfe;
73
- transition: width 0.3s;
74
- }
75
- .past-jobs {
76
- margin-top: 2rem;
77
- background: rgba(255,255,255,0.9);
78
- padding: 1rem;
79
- border-radius: 8px;
80
- width: 90%;
81
- max-width: 600px;
82
- }
83
- .job {
84
- display: flex;
85
- justify-content: space-between;
86
- margin: 0.5rem 0;
87
- padding: 0.5rem;
88
- background: #f9f9f9;
89
- border-radius: 4px;
90
- }
91
- .job.expired button {
92
- background: #ccc;
93
- cursor: not-allowed;
94
- }
95
- footer {
96
- position: fixed;
97
- bottom: 10px;
98
- left: 50%;
99
- transform: translateX(-50%);
100
- color: white;
101
- font-size: 0.9rem;
102
- opacity: 0.9;
103
- text-align: center;
104
- background: rgba(0, 0, 0, 0.25);
105
- padding: 0.4rem 0.8rem;
106
- border-radius: 8px;
107
- backdrop-filter: blur(4px);
108
- z-index: 999;
109
- }
110
-
111
- footer a {
112
- color: #fff;
113
- text-decoration: none;
114
- font-weight: bold;
115
- margin-left: 0.3rem;
116
- transition: opacity 0.2s;
117
- }
118
-
119
- footer a:hover {
120
- opacity: 0.8;
121
- }
122
-
123
- .coffee {
124
- display: inline-block;
125
- margin-left: 0.3rem;
126
- filter: brightness(0) invert(1);
127
- vertical-align: middle;
128
- width: 18px;
129
- height: 18px;
130
- }
131
  </style>
132
  </head>
133
  <body>
 
 
 
 
 
 
 
 
134
  <h1>PDF Token Splitter</h1>
135
  <p>Upload large PDFs and split them into custom token-sized chunks</p>
 
136
  <div class="upload-box">
137
  <input type="file" id="pdfFile" accept="application/pdf" multiple style="display:none;" />
138
  <label for="pdfFile" id="fileLabel" style="background:#4facfe;color:white;padding:0.5rem 1rem;border-radius:5px;cursor:pointer;">Choose PDF(s)</label>
139
  <div id="fileNames" style="margin-top:0.5rem;font-size:0.9rem;color:#333;"></div>
 
140
  <div class="slider-container">
141
  <label>Token Size:</label>
142
  <input type="range" id="tokenSize" min="500" max="500000" step="100" value="1000" />
143
  <input type="number" id="customTokenSize" min="500" value="1000" />
144
  </div>
 
145
  <button onclick="uploadFile()">Upload & Process</button>
146
- <div class="progress-bar"><div class="progress-bar-inner" id="progressInner"></div></div>
147
  <div class="counter">Used by <span id="usageCount">0</span> people</div>
148
  </div>
149
- <div class="past-jobs" id="pastJobs" style="display:none;">
150
- <h3>Past Jobs</h3>
151
- <div id="jobsList"></div>
152
- </div>
153
-
154
- <footer>
155
- Made with ❤️ by Rohit Sadanand ·
156
- <a href="https://buymeacoffee.com/anchoredlattice" target="_blank" rel="noopener noreferrer">
157
- <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy me a coffee" class="coffee" />
158
- Buy me a coffee
159
- </a>
160
- </footer>
161
 
162
  <script>
163
- let pastJobs = JSON.parse(localStorage.getItem('pastJobs') || '[]');
164
- const API_URL = window.API_URL || '';
165
  async function fetchCount() {
166
- const res = await fetch(API_URL + '/api/counter');
167
- const data = await res.json();
168
- document.getElementById('usageCount').innerText = data.count;
 
 
 
 
169
  }
 
170
  async function incrementCount() {
171
- await fetch(API_URL + '/api/increment', { method: 'POST' });
172
- fetchCount();
 
 
 
 
 
173
  }
 
174
  document.getElementById('tokenSize').addEventListener('input', function() {
175
  document.getElementById('customTokenSize').value = this.value;
176
  });
@@ -181,83 +142,20 @@ const API_URL = window.API_URL || '';
181
  const names = Array.from(this.files).map(f => f.name).join(', ');
182
  document.getElementById('fileNames').innerText = names || '';
183
  });
184
- function updateJobsUI() {
185
- const jobsList = document.getElementById('jobsList');
186
- jobsList.innerHTML = '';
187
- const now = Date.now();
188
- pastJobs.forEach(job => {
189
- const elapsed = now - job.timestamp;
190
- const expired = elapsed > 15 * 60 * 1000;
191
- const div = document.createElement('div');
192
- div.className = 'job' + (expired ? ' expired' : '');
193
- const span = document.createElement('span');
194
- span.textContent = job.filename;
195
- const button = document.createElement('button');
196
- button.textContent = 'Download';
197
- if (expired) {
198
- button.disabled = true;
199
- } else {
200
- button.onclick = () => downloadFile(job.job_id, job.filename);
201
- }
202
- div.appendChild(span);
203
- div.appendChild(button);
204
- jobsList.appendChild(div);
205
- });
206
- document.getElementById('pastJobs').style.display = pastJobs.length ? 'block' : 'none';
207
- localStorage.setItem('pastJobs', JSON.stringify(pastJobs));
208
- }
209
- async function downloadFile(jobId, filename) {
210
- const url = API_URL + '/download/' + jobId;
211
- const baseName = filename.replace(/\.[^/.]+$/, '');
212
- const downloadName = baseName + '_chunks.zip';
213
- try {
214
- const res = await fetch(url);
215
- if (!res.ok) throw new Error('File not found or expired');
216
- const blob = await res.blob();
217
- const link = document.createElement('a');
218
- link.href = window.URL.createObjectURL(blob);
219
- link.download = downloadName;
220
- link.click();
221
- } catch (err) {
222
- alert(err.message);
223
- }
224
- }
225
  async function uploadFile() {
226
- incrementCount();
 
227
  const fileInput = document.getElementById('pdfFile');
228
- const tokenSize = parseInt(document.getElementById('customTokenSize').value);
229
  if (!fileInput.files.length) {
230
  alert('Please select a PDF file');
231
  return;
232
  }
233
- const progressBar = document.querySelector('.progress-bar');
234
- const progressInner = document.getElementById('progressInner');
235
- progressBar.style.display = 'block';
236
- progressInner.style.width = '0%';
237
- let progress = 0;
238
- const interval = setInterval(() => {
239
- progress = Math.min(progress + 10, 90);
240
- progressInner.style.width = progress + '%';
241
- }, 300);
242
- const formData = new FormData();
243
- for (const f of fileInput.files) { formData.append('files', f); }
244
- formData.append('token_size', tokenSize);
245
- fetch(API_URL + '/api/upload', { method: 'POST', body: formData })
246
- .then(res => res.json())
247
- .then(data => {
248
- if (data.job_id) {
249
- pastJobs.unshift({ filename: data.filename, job_id: data.job_id, timestamp: Date.now() });
250
- updateJobsUI();
251
- } else {
252
- alert('Error processing file');
253
- }
254
- progressBar.style.display = 'none';
255
- clearInterval(interval);
256
- progressInner.style.width = '100%';
257
- });
258
  }
 
259
  fetchCount();
260
- updateJobsUI();
261
  </script>
262
  </body>
263
  </html>
 
16
  color: #333;
17
  min-height: 100vh;
18
  }
19
+ header {
20
+ width: 100%;
21
+ background: rgba(0, 0, 0, 0.15);
22
+ color: white;
23
+ text-align: center;
24
+ padding: 1rem 0.5rem;
25
+ backdrop-filter: blur(4px);
26
+ box-shadow: 0 2px 10px rgba(0,0,0,0.2);
27
+ }
28
+ header a {
29
+ color: #fff;
30
+ text-decoration: none;
31
+ font-weight: bold;
32
+ margin-left: 0.3rem;
33
+ transition: opacity 0.2s;
34
+ }
35
+ header a:hover { opacity: 0.85; }
36
+ .coffee {
37
+ display: inline-block;
38
+ margin-left: 0.3rem;
39
+ filter: brightness(0) invert(1);
40
+ vertical-align: middle;
41
+ width: 18px;
42
+ height: 18px;
43
+ }
44
  h1 {
45
  font-size: 2.5rem;
46
  margin-top: 2rem;
 
50
  font-size: 1.2rem;
51
  margin-bottom: 2rem;
52
  color: white;
53
+ text-align: center;
54
  }
55
  .upload-box {
56
  background: #f7f7f7;
 
60
  width: 350px;
61
  text-align: center;
62
  }
 
 
 
 
63
  .slider-container {
64
  margin: 1rem 0;
65
  text-align: left;
 
80
  button:hover {
81
  background: #3b8fe0;
82
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  </style>
84
  </head>
85
  <body>
86
+ <header>
87
+ <strong>Made with ❤️ by Rohit Sadanand</strong> ·
88
+ <a href="https://buymeacoffee.com/anchoredlattice" target="_blank" rel="noopener noreferrer">
89
+ <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy me a coffee" class="coffee" />
90
+ Buy me a coffee
91
+ </a>
92
+ </header>
93
+
94
  <h1>PDF Token Splitter</h1>
95
  <p>Upload large PDFs and split them into custom token-sized chunks</p>
96
+
97
  <div class="upload-box">
98
  <input type="file" id="pdfFile" accept="application/pdf" multiple style="display:none;" />
99
  <label for="pdfFile" id="fileLabel" style="background:#4facfe;color:white;padding:0.5rem 1rem;border-radius:5px;cursor:pointer;">Choose PDF(s)</label>
100
  <div id="fileNames" style="margin-top:0.5rem;font-size:0.9rem;color:#333;"></div>
101
+
102
  <div class="slider-container">
103
  <label>Token Size:</label>
104
  <input type="range" id="tokenSize" min="500" max="500000" step="100" value="1000" />
105
  <input type="number" id="customTokenSize" min="500" value="1000" />
106
  </div>
107
+
108
  <button onclick="uploadFile()">Upload & Process</button>
 
109
  <div class="counter">Used by <span id="usageCount">0</span> people</div>
110
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  <script>
113
+ const API_URL = window.API_URL || '';
114
+
115
  async function fetchCount() {
116
+ try {
117
+ const res = await fetch(API_URL + '/api/count');
118
+ const data = await res.json();
119
+ document.getElementById('usageCount').innerText = data.count;
120
+ } catch (err) {
121
+ console.error('Failed to load count:', err);
122
+ }
123
  }
124
+
125
  async function incrementCount() {
126
+ try {
127
+ const res = await fetch(API_URL + '/api/increment', { method: 'POST' });
128
+ const data = await res.json();
129
+ document.getElementById('usageCount').innerText = data.count;
130
+ } catch (err) {
131
+ console.error('Failed to increment count:', err);
132
+ }
133
  }
134
+
135
  document.getElementById('tokenSize').addEventListener('input', function() {
136
  document.getElementById('customTokenSize').value = this.value;
137
  });
 
142
  const names = Array.from(this.files).map(f => f.name).join(', ');
143
  document.getElementById('fileNames').innerText = names || '';
144
  });
145
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  async function uploadFile() {
147
+ incrementCount(); // increments backend counter
148
+
149
  const fileInput = document.getElementById('pdfFile');
 
150
  if (!fileInput.files.length) {
151
  alert('Please select a PDF file');
152
  return;
153
  }
154
+
155
+ alert('Pretending to upload file... counter incremented!');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
+
158
  fetchCount();
 
159
  </script>
160
  </body>
161
  </html>