prthm11 commited on
Commit
1fe061a
·
verified ·
1 Parent(s): b1fb4e5

Update templates/app_index.html

Browse files
Files changed (1) hide show
  1. templates/app_index.html +79 -125
templates/app_index.html CHANGED
@@ -1,125 +1,79 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>PDF Image Captioning</title>
6
- <style>
7
- body {
8
- font-family: Arial, sans-serif;
9
- margin: 30px;
10
- background-color: #f9f9f9;
11
- }
12
-
13
- h2 {
14
- margin-bottom: 10px;
15
- }
16
-
17
- input[type="text"] {
18
- width: 60%;
19
- padding: 8px;
20
- margin-right: 10px;
21
- }
22
-
23
- button {
24
- padding: 8px 16px;
25
- cursor: pointer;
26
- }
27
-
28
- .sprite {
29
- display: inline-block;
30
- margin: 20px;
31
- border: 1px solid #ccc;
32
- padding: 10px;
33
- background: white;
34
- width: 250px;
35
- vertical-align: top;
36
- }
37
-
38
- .sprite img {
39
- width: 100%;
40
- height: auto;
41
- margin-bottom: 10px;
42
- }
43
-
44
- .sprite h4, .sprite p {
45
- margin: 4px 0;
46
- }
47
-
48
- #result-container {
49
- margin-top: 30px;
50
- }
51
-
52
- #status {
53
- margin-top: 20px;
54
- font-weight: bold;
55
- }
56
- </style>
57
- </head>
58
- <body>
59
- <h2>PDF Sprite Image Captioning</h2>
60
-
61
- <input type="text" id="pdfPath" placeholder="Enter full PDF path (e.g., E:/folder/sample.pdf)">
62
- <button onclick="processPDF()">Process PDF</button>
63
-
64
- <div id="status"></div>
65
- <div id="result-container"></div>
66
-
67
- <script>
68
- async function processPDF() {
69
- const pdfPath = document.getElementById("pdfPath").value.trim();
70
- const statusEl = document.getElementById("status");
71
- const resultContainer = document.getElementById("result-container");
72
-
73
- if (!pdfPath) {
74
- alert("Please enter a valid PDF path.");
75
- return;
76
- }
77
-
78
- statusEl.textContent = "Processing PDF...";
79
- resultContainer.innerHTML = "";
80
-
81
- try {
82
- const response = await fetch("/process_pdf", {
83
- method: "POST",
84
- headers: {
85
- "Content-Type": "application/json"
86
- },
87
- body: JSON.stringify({ pdf_path: pdfPath })
88
- });
89
-
90
- const result = await response.json();
91
-
92
- if (!response.ok) {
93
- throw new Error(result.error || "Unknown error");
94
- }
95
-
96
- statusEl.textContent = result.message;
97
-
98
- const sprites = result.sprites;
99
- for (const [key, sprite] of Object.entries(sprites)) {
100
- const div = document.createElement("div");
101
- div.className = "sprite";
102
-
103
- const img = document.createElement("img");
104
- img.src = `data:image/png;base64,${sprite.base64}`;
105
-
106
- const name = document.createElement("h4");
107
- name.textContent = sprite.name || "No name";
108
-
109
- const desc = document.createElement("p");
110
- desc.textContent = sprite.description || "No description";
111
-
112
- div.appendChild(img);
113
- div.appendChild(name);
114
- div.appendChild(desc);
115
-
116
- resultContainer.appendChild(div);
117
- }
118
-
119
- } catch (err) {
120
- statusEl.textContent = "❌ Error: " + err.message;
121
- }
122
- }
123
- </script>
124
- </body>
125
- </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Upload PDF for Sprite Extraction</title>
6
+ <style>
7
+ body { font-family: Arial; padding: 20px; background: #f5f5f5; }
8
+ .sprite { margin: 20px; padding: 10px; background: white; border: 1px solid #ccc; display: inline-block; width: 250px; }
9
+ .sprite img { width: 100%; }
10
+ #status { margin-top: 15px; font-weight: bold; }
11
+ </style>
12
+ </head>
13
+ <body>
14
+ <h2>Upload PDF for Image Extraction and Captioning</h2>
15
+ <form id="pdfForm" enctype="multipart/form-data">
16
+ <input type="file" id="pdfFile" name="pdf_file" accept="application/pdf">
17
+ <button type="submit">Upload & Process</button>
18
+ </form>
19
+
20
+ <div id="status"></div>
21
+ <div id="result-container"></div>
22
+
23
+ <script>
24
+ const form = document.getElementById('pdfForm');
25
+ const statusEl = document.getElementById('status');
26
+ const resultEl = document.getElementById('result-container');
27
+
28
+ form.addEventListener('submit', async (e) => {
29
+ e.preventDefault();
30
+ const fileInput = document.getElementById('pdfFile');
31
+ if (!fileInput.files[0]) {
32
+ alert('Please select a PDF file.');
33
+ return;
34
+ }
35
+
36
+ statusEl.textContent = 'Uploading and processing...';
37
+ resultEl.innerHTML = '';
38
+
39
+ const formData = new FormData();
40
+ formData.append('pdf_file', fileInput.files[0]);
41
+
42
+ try {
43
+ const res = await fetch('/process_pdf', {
44
+ method: 'POST',
45
+ body: formData
46
+ });
47
+
48
+ const data = await res.json();
49
+ if (!res.ok) throw new Error(data.error || 'Upload failed');
50
+
51
+ statusEl.textContent = data.message;
52
+
53
+ const sprites = data.sprites;
54
+ for (const [key, sprite] of Object.entries(sprites)) {
55
+ const div = document.createElement('div');
56
+ div.className = 'sprite';
57
+
58
+ const img = document.createElement('img');
59
+ img.src = `data:image/png;base64,${sprite.base64}`;
60
+
61
+ const name = document.createElement('h4');
62
+ name.textContent = sprite.name;
63
+
64
+ const desc = document.createElement('p');
65
+ desc.textContent = sprite.description;
66
+
67
+ div.appendChild(img);
68
+ div.appendChild(name);
69
+ div.appendChild(desc);
70
+ resultEl.appendChild(div);
71
+ }
72
+
73
+ } catch (err) {
74
+ statusEl.textContent = `❌ Error: ${err.message}`;
75
+ }
76
+ });
77
+ </script>
78
+ </body>
79
+ </html>