Spaces:
Runtime error
Runtime error
| /* classify uploaded images using a Huggingface model */ | |
| async function classifyImages(acceptedFiles) { | |
| let formData = new FormData(); | |
| for (const file of acceptedFiles){ | |
| formData.append('files', file); | |
| } | |
| let classifyResponse = await fetch('classify', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| return classifyResponse; | |
| } | |
| const inputDoc = document.getElementById('doc-input'); | |
| const outputDocLink = document.getElementById('doc-output-link'); | |
| inputDoc.addEventListener("change", async event =>{ | |
| /* hide Download button when in classification process */ | |
| // outputDocLink.style.visibility = "hidden"; | |
| // dlOutputBtn.disabled = true; | |
| outputDocLink.ariaDisabled = "true"; | |
| outputDocLink.classList.add("disabled"); | |
| const files = event.target.files; | |
| /* make Download button's visible, and add the link to download the resulting .csv file */ | |
| await classifyImages(files).then(async (result) => { | |
| // outputDocLink.style.visibility = "visible"; | |
| // dlOutputBtn.disabled = false; | |
| outputDocLink.ariaDisabled = "false"; | |
| outputDocLink.classList.remove("disabled"); | |
| const disposition = result.headers.get('Content-Disposition'); | |
| const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; | |
| const matches = filenameRegex.exec(disposition); | |
| // const filename = matches != null && matches[1] ? matches[1].replace(/['"]/g, '') : 'data.csv'; | |
| const filename = 'data.csv'; | |
| const blob = await result.blob(); | |
| const url = window.URL.createObjectURL(blob); | |
| // set download link to the download button | |
| outputDocLink.href = url; | |
| }); | |
| }); |