Spaces:
Sleeping
Sleeping
Update templates/app_index.html
Browse files- 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
|
6 |
-
<style>
|
7 |
-
body {
|
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 |
-
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|