Spaces:
Runtime error
Runtime error
Download src/app/static/app.js from welcometoFightclub/datacollection_server: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/spaces/welcometoFightclub/datacollection_server/resolve/main/src/app/static/app.js
- Command line
-
hf download hf://spaces/welcometoFightclub/datacollection_server/src/app/static/app.js
-
curl -L -o app.js https://huggingface.co/spaces/welcometoFightclub/datacollection_server/resolve/main/src/app/static/app.js
2.29 kB
| const form = document.querySelector("#upload-form"); | |
| const input = document.querySelector("#document"); | |
| const button = document.querySelector("#submit"); | |
| const statusText = document.querySelector("#status"); | |
| const result = document.querySelector("#result"); | |
| const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)); | |
| function showStatus(message, isError = false) { | |
| statusText.textContent = message; | |
| statusText.className = isError ? "error" : ""; | |
| } | |
| async function readError(response) { | |
| const body = await response.json().catch(() => null); | |
| return body?.error?.message || body?.detail || "The request failed."; | |
| } | |
| async function pollJob(jobId) { | |
| const deadline = Date.now() + 15 * 60 * 1000; | |
| while (Date.now() < deadline) { | |
| const response = await fetch(`/api/v1/jobs/${jobId}`); | |
| if (!response.ok) throw new Error(await readError(response)); | |
| const job = await response.json(); | |
| showStatus(`Status: ${job.status}`); | |
| if (job.status === "COMPLETED") { | |
| const resultResponse = await fetch(`/api/v1/jobs/${jobId}/result`); | |
| if (!resultResponse.ok) throw new Error(await readError(resultResponse)); | |
| result.textContent = JSON.stringify(await resultResponse.json(), null, 2); | |
| return; | |
| } | |
| if (job.status === "FAILED" || job.status === "CANCELLED") { | |
| throw new Error(job.error?.message || "Extraction failed."); | |
| } | |
| await sleep(2500); | |
| } | |
| showStatus("Processing is taking longer than expected. Refresh this page later."); | |
| } | |
| form.addEventListener("submit", async (event) => { | |
| event.preventDefault(); | |
| const file = input.files[0]; | |
| if (!file) return; | |
| button.disabled = true; | |
| result.textContent = "Waiting for extraction…"; | |
| showStatus("Uploading document…"); | |
| try { | |
| const body = new FormData(); | |
| body.append("file", file); | |
| const response = await fetch("/api/v1/documents", { method: "POST", body }); | |
| if (!response.ok) throw new Error(await readError(response)); | |
| const job = await response.json(); | |
| showStatus(`Status: ${job.status}. Extraction started.`); | |
| await pollJob(job.job_id); | |
| } catch (error) { | |
| showStatus(error.message, true); | |
| result.textContent = "No extraction result is available."; | |
| } finally { | |
| button.disabled = false; | |
| } | |
| }); | |