saifisvibin commited on
Commit
e963d81
·
verified ·
1 Parent(s): 5ad1ee4

Delete example_client.html

Browse files
Files changed (1) hide show
  1. example_client.html +0 -447
example_client.html DELETED
@@ -1,447 +0,0 @@
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.0">
6
- <title>PDF Extractor API - Client Example</title>
7
- <style>
8
- * {
9
- margin: 0;
10
- padding: 0;
11
- box-sizing: border-box;
12
- }
13
- body {
14
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
15
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
16
- min-height: 100vh;
17
- padding: 20px;
18
- }
19
- .container {
20
- max-width: 1200px;
21
- margin: 0 auto;
22
- background: white;
23
- border-radius: 12px;
24
- box-shadow: 0 10px 40px rgba(0,0,0,0.2);
25
- padding: 30px;
26
- }
27
- h1 {
28
- color: #333;
29
- margin-bottom: 10px;
30
- }
31
- .subtitle {
32
- color: #666;
33
- margin-bottom: 30px;
34
- }
35
- .upload-section {
36
- border: 2px dashed #667eea;
37
- border-radius: 8px;
38
- padding: 40px;
39
- text-align: center;
40
- margin-bottom: 30px;
41
- background: #f8f9ff;
42
- }
43
- .file-input-wrapper {
44
- position: relative;
45
- display: inline-block;
46
- }
47
- input[type="file"] {
48
- display: none;
49
- }
50
- .file-label {
51
- display: inline-block;
52
- padding: 12px 24px;
53
- background: #667eea;
54
- color: white;
55
- border-radius: 6px;
56
- cursor: pointer;
57
- font-weight: 500;
58
- transition: background 0.3s;
59
- }
60
- .file-label:hover {
61
- background: #5568d3;
62
- }
63
- .selected-file {
64
- margin-top: 15px;
65
- color: #333;
66
- font-weight: 500;
67
- }
68
- .mode-selection {
69
- display: flex;
70
- gap: 10px;
71
- justify-content: center;
72
- margin: 20px 0;
73
- }
74
- .mode-btn {
75
- padding: 10px 20px;
76
- border: 2px solid #667eea;
77
- background: white;
78
- color: #667eea;
79
- border-radius: 6px;
80
- cursor: pointer;
81
- transition: all 0.3s;
82
- }
83
- .mode-btn.active {
84
- background: #667eea;
85
- color: white;
86
- }
87
- .submit-btn {
88
- padding: 12px 30px;
89
- background: #667eea;
90
- color: white;
91
- border: none;
92
- border-radius: 6px;
93
- font-size: 16px;
94
- font-weight: 600;
95
- cursor: pointer;
96
- transition: background 0.3s;
97
- margin-top: 20px;
98
- }
99
- .submit-btn:hover:not(:disabled) {
100
- background: #5568d3;
101
- }
102
- .submit-btn:disabled {
103
- background: #ccc;
104
- cursor: not-allowed;
105
- }
106
- .progress-section {
107
- display: none;
108
- margin: 30px 0;
109
- }
110
- .progress-bar-container {
111
- background: #e0e0e0;
112
- border-radius: 10px;
113
- height: 30px;
114
- overflow: hidden;
115
- margin: 10px 0;
116
- }
117
- .progress-bar {
118
- background: linear-gradient(90deg, #667eea, #764ba2);
119
- height: 100%;
120
- width: 0%;
121
- transition: width 0.3s;
122
- display: flex;
123
- align-items: center;
124
- justify-content: center;
125
- color: white;
126
- font-weight: 600;
127
- font-size: 14px;
128
- }
129
- .status-message {
130
- text-align: center;
131
- color: #666;
132
- margin-top: 10px;
133
- }
134
- .results-section {
135
- display: none;
136
- margin-top: 30px;
137
- }
138
- .result-card {
139
- background: #f8f9ff;
140
- border-radius: 8px;
141
- padding: 20px;
142
- margin: 15px 0;
143
- }
144
- .result-card h3 {
145
- color: #667eea;
146
- margin-bottom: 15px;
147
- }
148
- .summary-grid {
149
- display: grid;
150
- grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
151
- gap: 15px;
152
- margin: 20px 0;
153
- }
154
- .summary-item {
155
- background: white;
156
- padding: 15px;
157
- border-radius: 6px;
158
- text-align: center;
159
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
160
- }
161
- .summary-value {
162
- font-size: 24px;
163
- font-weight: 700;
164
- color: #667eea;
165
- }
166
- .summary-label {
167
- color: #666;
168
- font-size: 14px;
169
- margin-top: 5px;
170
- }
171
- .text-preview {
172
- background: white;
173
- border: 1px solid #ddd;
174
- border-radius: 6px;
175
- padding: 15px;
176
- max-height: 300px;
177
- overflow-y: auto;
178
- font-family: 'Courier New', monospace;
179
- font-size: 14px;
180
- white-space: pre-wrap;
181
- }
182
- .images-grid {
183
- display: grid;
184
- grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
185
- gap: 15px;
186
- margin: 20px 0;
187
- }
188
- .image-item {
189
- background: white;
190
- border: 1px solid #ddd;
191
- border-radius: 6px;
192
- overflow: hidden;
193
- }
194
- .image-item img {
195
- width: 100%;
196
- height: auto;
197
- display: block;
198
- }
199
- .image-caption {
200
- padding: 10px;
201
- font-size: 12px;
202
- color: #666;
203
- }
204
- .error {
205
- background: #fee;
206
- color: #c33;
207
- padding: 15px;
208
- border-radius: 6px;
209
- margin: 20px 0;
210
- border-left: 4px solid #c33;
211
- }
212
- .api-info {
213
- background: #e8f4f8;
214
- border-left: 4px solid #2196F3;
215
- padding: 15px;
216
- border-radius: 6px;
217
- margin-bottom: 20px;
218
- }
219
- .api-info code {
220
- background: white;
221
- padding: 2px 6px;
222
- border-radius: 3px;
223
- font-size: 13px;
224
- }
225
- </style>
226
- </head>
227
- <body>
228
- <div class="container">
229
- <h1>📄 PDF Layout Extractor - API Client</h1>
230
- <p class="subtitle">Upload a PDF and extract text, tables, and figures using the REST API</p>
231
-
232
- <div class="api-info">
233
- <strong>API Endpoint:</strong> <code>https://saifisvibin-volaris-pdf-tool.hf.space/api/predict</code><br>
234
- <strong>Method:</strong> <code>POST</code> | <strong>Content-Type:</strong> <code>multipart/form-data</code>
235
- </div>
236
-
237
- <div class="upload-section">
238
- <h2>Upload PDF File</h2>
239
- <div class="file-input-wrapper">
240
- <input type="file" id="fileInput" accept=".pdf" />
241
- <label for="fileInput" class="file-label">Choose PDF File</label>
242
- </div>
243
- <div class="selected-file" id="selectedFile"></div>
244
-
245
- <div class="mode-selection">
246
- <button class="mode-btn active" data-mode="both">Both (Images + Markdown)</button>
247
- <button class="mode-btn" data-mode="images">Images Only</button>
248
- <button class="mode-btn" data-mode="markdown">Markdown Only</button>
249
- </div>
250
-
251
- <button class="submit-btn" id="submitBtn" onclick="processPDF()">Process PDF</button>
252
- </div>
253
-
254
- <div class="progress-section" id="progressSection">
255
- <h3>Processing...</h3>
256
- <div class="progress-bar-container">
257
- <div class="progress-bar" id="progressBar">0%</div>
258
- </div>
259
- <div class="status-message" id="statusMessage">Starting...</div>
260
- </div>
261
-
262
- <div class="error" id="errorMessage" style="display: none;"></div>
263
-
264
- <div class="results-section" id="resultsSection">
265
- <h2>Extraction Results</h2>
266
-
267
- <div class="summary-grid" id="summaryGrid"></div>
268
-
269
- <div class="result-card">
270
- <h3>📝 Extracted Text</h3>
271
- <div class="text-preview" id="textPreview"></div>
272
- </div>
273
-
274
- <div class="result-card" id="figuresCard" style="display: none;">
275
- <h3>🖼️ Figures (<span id="figuresCount">0</span>)</h3>
276
- <div class="images-grid" id="figuresGrid"></div>
277
- </div>
278
-
279
- <div class="result-card" id="tablesCard" style="display: none;">
280
- <h3>📊 Tables (<span id="tablesCount">0</span>)</h3>
281
- <div class="images-grid" id="tablesGrid"></div>
282
- </div>
283
- </div>
284
- </div>
285
-
286
- <script>
287
- const API_URL = 'https://saifisvibin-volaris-pdf-tool.hf.space/api/predict';
288
- let selectedMode = 'both';
289
-
290
- // File input handler
291
- document.getElementById('fileInput').addEventListener('change', function(e) {
292
- const file = e.target.files[0];
293
- if (file) {
294
- document.getElementById('selectedFile').textContent = `Selected: ${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`;
295
- }
296
- });
297
-
298
- // Mode selection
299
- document.querySelectorAll('.mode-btn').forEach(btn => {
300
- btn.addEventListener('click', function() {
301
- document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
302
- this.classList.add('active');
303
- selectedMode = this.dataset.mode;
304
- });
305
- });
306
-
307
- async function processPDF() {
308
- const fileInput = document.getElementById('fileInput');
309
- const file = fileInput.files[0];
310
-
311
- if (!file) {
312
- showError('Please select a PDF file');
313
- return;
314
- }
315
-
316
- // Reset UI
317
- document.getElementById('errorMessage').style.display = 'none';
318
- document.getElementById('resultsSection').style.display = 'none';
319
- document.getElementById('progressSection').style.display = 'block';
320
- document.getElementById('progressBar').style.width = '0%';
321
- document.getElementById('progressBar').textContent = '0%';
322
- document.getElementById('statusMessage').textContent = 'Uploading and processing...';
323
- document.getElementById('submitBtn').disabled = true;
324
-
325
- try {
326
- const formData = new FormData();
327
- formData.append('file', file);
328
-
329
- const response = await fetch(API_URL, {
330
- method: 'POST',
331
- body: formData
332
- });
333
-
334
- if (!response.ok) {
335
- const errorData = await response.json().catch(() => ({ error: response.statusText }));
336
- throw new Error(errorData.error || `HTTP ${response.status}: ${response.statusText}`);
337
- }
338
-
339
- const result = await response.json();
340
-
341
- if (result.status === 'error') {
342
- throw new Error(result.error);
343
- }
344
-
345
- // Update progress to 100%
346
- document.getElementById('progressBar').style.width = '100%';
347
- document.getElementById('progressBar').textContent = '100%';
348
- document.getElementById('statusMessage').textContent = 'Processing complete!';
349
-
350
- // Display results
351
- displayResults(result);
352
-
353
- } catch (error) {
354
- console.error('Error:', error);
355
- showError(error.message || 'An error occurred while processing the PDF');
356
- document.getElementById('progressSection').style.display = 'none';
357
- } finally {
358
- document.getElementById('submitBtn').disabled = false;
359
- }
360
- }
361
-
362
- function displayResults(result) {
363
- // Hide progress, show results
364
- document.getElementById('progressSection').style.display = 'none';
365
- document.getElementById('resultsSection').style.display = 'block';
366
-
367
- // Summary
368
- const summary = result.summary || {};
369
- document.getElementById('summaryGrid').innerHTML = `
370
- <div class="summary-item">
371
- <div class="summary-value">${summary.total_pages || 0}</div>
372
- <div class="summary-label">Total Pages</div>
373
- </div>
374
- <div class="summary-item">
375
- <div class="summary-value">${summary.figures_count || 0}</div>
376
- <div class="summary-label">Figures</div>
377
- </div>
378
- <div class="summary-item">
379
- <div class="summary-value">${summary.tables_count || 0}</div>
380
- <div class="summary-label">Tables</div>
381
- </div>
382
- <div class="summary-item">
383
- <div class="summary-value">${summary.elements_count || 0}</div>
384
- <div class="summary-label">Total Elements</div>
385
- </div>
386
- `;
387
-
388
- // Text
389
- const textPreview = document.getElementById('textPreview');
390
- if (result.text && result.text.trim()) {
391
- textPreview.textContent = result.text;
392
- } else {
393
- textPreview.textContent = 'No text extracted.';
394
- }
395
-
396
- // Figures
397
- const figuresCard = document.getElementById('figuresCard');
398
- const figuresGrid = document.getElementById('figuresGrid');
399
- const figuresCount = document.getElementById('figuresCount');
400
-
401
- if (result.figures && result.figures.length > 0) {
402
- figuresCard.style.display = 'block';
403
- figuresCount.textContent = result.figures.length;
404
- figuresGrid.innerHTML = result.figures.map((fig, idx) => `
405
- <div class="image-item">
406
- <img src="${fig.image_base64 || ''}" alt="Figure ${idx + 1}" />
407
- <div class="image-caption">
408
- <strong>Figure ${idx + 1}</strong><br>
409
- Page ${fig.page} | Confidence: ${(fig.confidence * 100).toFixed(1)}%
410
- </div>
411
- </div>
412
- `).join('');
413
- } else {
414
- figuresCard.style.display = 'none';
415
- }
416
-
417
- // Tables
418
- const tablesCard = document.getElementById('tablesCard');
419
- const tablesGrid = document.getElementById('tablesGrid');
420
- const tablesCount = document.getElementById('tablesCount');
421
-
422
- if (result.tables && result.tables.length > 0) {
423
- tablesCard.style.display = 'block';
424
- tablesCount.textContent = result.tables.length;
425
- tablesGrid.innerHTML = result.tables.map((tab, idx) => `
426
- <div class="image-item">
427
- <img src="${tab.image_base64 || ''}" alt="Table ${idx + 1}" />
428
- <div class="image-caption">
429
- <strong>Table ${idx + 1}</strong><br>
430
- Page ${tab.page} | Confidence: ${(tab.confidence * 100).toFixed(1)}%
431
- </div>
432
- </div>
433
- `).join('');
434
- } else {
435
- tablesCard.style.display = 'none';
436
- }
437
- }
438
-
439
- function showError(message) {
440
- const errorDiv = document.getElementById('errorMessage');
441
- errorDiv.textContent = `Error: ${message}`;
442
- errorDiv.style.display = 'block';
443
- }
444
- </script>
445
- </body>
446
- </html>
447
-