Spaces:
Sleeping
Sleeping
Update templates/app_index.html
Browse files- templates/app_index.html +38 -92
templates/app_index.html
CHANGED
|
@@ -1,93 +1,39 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
|
| 4 |
-
<
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
|
| 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 |
-
</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>
|