WebashalarForML commited on
Commit
f67c2f0
·
verified ·
1 Parent(s): f6d5d4e

Update templates/app_index.html

Browse files
Files changed (1) hide show
  1. templates/app_index.html +38 -92
templates/app_index.html CHANGED
@@ -1,93 +1,39 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <title>Upload PDF for Sprite Extraction</title>
7
- <style>
8
- body {
9
- font-family: Arial;
10
- padding: 20px;
11
- background: #f5f5f5;
12
- }
13
-
14
- .sprite {
15
- margin: 20px;
16
- padding: 10px;
17
- background: white;
18
- border: 1px solid #ccc;
19
- display: inline-block;
20
- width: 250px;
21
- }
22
-
23
- .sprite img {
24
- width: 100%;
25
- }
26
-
27
- #status {
28
- margin-top: 15px;
29
- font-weight: bold;
30
- }
31
- </style>
32
- </head>
33
-
34
- <body>
35
- <h2>Upload PDF for Image Extraction and Captioning</h2>
36
- <form id="pdfForm" enctype="multipart/form-data">
37
- <input type="file" id="pdfFile" name="pdf_file" accept="application/pdf">
38
- <button type="submit">Upload & Process</button>
39
- </form>
40
-
41
- <div id="status"></div>
42
- <div id="result-container"></div>
43
-
44
- <script>
45
- const form = document.getElementById('pdfForm');
46
- const statusEl = document.getElementById('status');
47
- const resultEl = document.getElementById('result-container');
48
- form.addEventListener('submit', async (e) => {
49
- e.preventDefault();
50
- const fileInput = document.getElementById('pdfFile');
51
- if (!fileInput.files[0]) {
52
- alert('Please select a PDF file.');
53
- return;
54
- }
55
- statusEl.textContent = 'Uploading and processing...';
56
- resultEl.innerHTML = '';
57
- const formData = new FormData();
58
- formData.append('pdf_file', fileInput.files[0]);
59
- try {
60
- const res = await fetch('/process_pdf', {
61
- method: 'POST',
62
- body: formData
63
- });
64
- const data = await res.json();
65
- if (!res.ok) throw new Error(data.error || 'Upload failed');
66
- statusEl.textContent = data.message;
67
- const sprites = data.sprites;
68
- if (!sprites || typeof sprites !== "object") {
69
- statusEl.textContent = '⚠️ No valid sprite data received.';
70
- return;
71
- }
72
- for (const [key, sprite] of Object.entries(sprites)) {
73
- const div = document.createElement('div');
74
- div.className = 'sprite';
75
- const img = document.createElement('img');
76
- img.src = `data:image/png;base64,${sprite.base64}`;
77
- const name = document.createElement('h4');
78
- name.textContent = sprite.name;
79
- const desc = document.createElement('p');
80
- desc.textContent = sprite.description;
81
- div.appendChild(img);
82
- div.appendChild(name);
83
- div.appendChild(desc);
84
- resultEl.appendChild(div);
85
- }
86
- } catch (err) {
87
- statusEl.textContent = `❌ Error: ${err.message}`;
88
- }
89
- });
90
- </script>
91
- </body>
92
-
93
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Show JSON Response</title>
6
+ <style>
7
+ body { font-family: sans-serif; padding: 20px; }
8
+ button { padding: 8px 12px; }
9
+ pre { background: #f0f0f0; padding: 10px; border: 1px solid #ccc; margin-top: 10px; }
10
+ </style>
11
+ </head>
12
+ <body>
13
+
14
+ <h2>Fetch & Show JSON</h2>
15
+ <button id="fetchBtn">Fetch JSON</button>
16
+ <pre id="jsonOutput">Click the button to load JSON…</pre>
17
+
18
+ <script>
19
+ document.getElementById('fetchBtn').addEventListener('click', async () => {
20
+ const output = document.getElementById('jsonOutput');
21
+ output.textContent = 'Loading…';
22
+
23
+ try {
24
+ const res = await fetch('/process_pdf', { method: 'POST' /*, body: formData if needed */ });
25
+ const data = await res.json();
26
+ if (!res.ok) {
27
+ output.textContent = `Error ${res.status}: ${data.error || JSON.stringify(data)}`;
28
+ } else {
29
+ // Pretty-print the entire JSON object
30
+ output.textContent = JSON.stringify(data, null, 2);
31
+ }
32
+ } catch (err) {
33
+ output.textContent = `Fetch failed: ${err.message}`;
34
+ }
35
+ });
36
+ </script>
37
+
38
+ </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  </html>