Spaces:
Runtime error
Runtime error
Download app/static/js/main.js from progressive-intelligence-lab/docuflow: direct link, hf CLI and curl.
- Browser
- Download file 5.08 kB
-
https://huggingface.co/spaces/progressive-intelligence-lab/docuflow/resolve/main/app/static/js/main.js
- Command line
-
hf download hf://spaces/progressive-intelligence-lab/docuflow/app/static/js/main.js
-
curl -L -o main.js https://huggingface.co/spaces/progressive-intelligence-lab/docuflow/resolve/main/app/static/js/main.js
5.08 kB
| let currentDocumentId = null; | |
| async function uploadDocument() { | |
| const fileInput = document.getElementById("file"); | |
| const uploadButton = document.getElementById("uploadButton"); | |
| const uploadSpinner = document.getElementById("uploadSpinner"); | |
| const uploadButtonText = uploadButton.querySelector(".btn-text"); | |
| const file = fileInput.files[0]; | |
| if (!file) { | |
| alert("ํ์ผ์ ์ ํํด์ฃผ์ธ์."); | |
| return; | |
| } | |
| uploadButton.disabled = true; | |
| uploadSpinner.classList.remove("hidden"); | |
| uploadButtonText.classList.add("hidden"); | |
| const formData = new FormData(); | |
| formData.append("file", file); | |
| try { | |
| const uploadResponse = await fetch("/documents/", { | |
| method: "POST", | |
| body: formData, | |
| }); | |
| if (!uploadResponse.ok) { | |
| const errorData = await uploadResponse | |
| .json() | |
| .catch(() => ({ detail: uploadResponse.statusText })); | |
| throw new Error( | |
| `๋ฌธ์ ์ฒ๋ฆฌ ์คํจ: ${errorData.detail || uploadResponse.status}` | |
| ); | |
| } | |
| const uploadData = await uploadResponse.json(); | |
| currentDocumentId = uploadData.document_id; | |
| document.getElementById("qaDocumentIdDisplay").textContent = | |
| currentDocumentId; | |
| document.getElementById("qaFileNameDisplay").textContent = file.name; | |
| document.getElementById("upload-section").classList.add("hidden"); | |
| document.getElementById("qa-section").classList.remove("hidden"); | |
| document.getElementById("askButton").disabled = false; | |
| } catch (error) { | |
| console.error("Error:", error); | |
| alert(`์ค๋ฅ ๋ฐ์: ${error.message}`); | |
| } finally { | |
| uploadSpinner.classList.add("hidden"); | |
| uploadButtonText.classList.remove("hidden"); | |
| uploadButton.disabled = false; | |
| } | |
| } | |
| async function askQuestion() { | |
| const questionInput = document.getElementById("question"); | |
| const question = questionInput.value; | |
| const askButton = document.getElementById("askButton"); | |
| const answerDiv = document.getElementById("answer"); | |
| const loadingSpinner = document.getElementById("loadingSpinner"); | |
| const answerContainer = document.getElementById("answer-container"); | |
| const askButtonText = askButton.querySelector(".btn-text"); | |
| if (!question) { | |
| alert("์ง๋ฌธ์ ์ ๋ ฅํด์ฃผ์ธ์."); | |
| return; | |
| } | |
| if (!currentDocumentId) { | |
| alert("๋ฌธ์๋ฅผ ๋จผ์ ์ ๋ก๋ํด์ฃผ์ธ์."); | |
| return; | |
| } | |
| try { | |
| askButton.disabled = true; | |
| loadingSpinner.classList.remove("hidden"); | |
| askButtonText.classList.add("hidden"); | |
| answerDiv.textContent = ""; | |
| answerContainer.classList.remove("hidden"); | |
| answerDiv.classList.add("hidden"); | |
| const response = await fetch("/qa", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify({ | |
| query: question, | |
| document_id: currentDocumentId, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| answerDiv.textContent = data.answer; | |
| } catch (error) { | |
| console.error("Error:", error); | |
| answerDiv.textContent = `์ค๋ฅ ๋ฐ์: ${error.message}`; | |
| } finally { | |
| askButton.disabled = false; | |
| loadingSpinner.classList.add("hidden"); | |
| askButtonText.classList.remove("hidden"); | |
| answerDiv.classList.remove("hidden"); | |
| } | |
| } | |
| document.addEventListener("DOMContentLoaded", function () { | |
| const uploadButton = document.getElementById("uploadButton"); | |
| uploadButton.addEventListener("click", uploadDocument); | |
| const askButton = document.getElementById("askButton"); | |
| askButton.addEventListener("click", askQuestion); | |
| const fileInput = document.getElementById("file"); | |
| const fileNameSpan = document.getElementById("fileName"); | |
| fileInput.addEventListener("change", function () { | |
| const uploadButton = document.getElementById("uploadButton"); | |
| if (fileInput.files.length > 0) { | |
| fileNameSpan.textContent = fileInput.files[0].name; | |
| uploadButton.classList.remove("hidden"); | |
| } else { | |
| fileNameSpan.textContent = "์ ํ๋ ํ์ผ ์์"; | |
| uploadButton.classList.add("hidden"); | |
| } | |
| }); | |
| const backButton = document.getElementById("backButton"); | |
| backButton.addEventListener("click", function () { | |
| // Hide QA section, show Upload section | |
| document.getElementById("qa-section").classList.add("hidden"); | |
| document.getElementById("upload-section").classList.remove("hidden"); | |
| // Reset state | |
| currentDocumentId = null; | |
| document.getElementById("question").value = ""; | |
| document.getElementById("answer").textContent = ""; | |
| document.getElementById("answer-container").classList.add("hidden"); | |
| document.getElementById("askButton").disabled = true; | |
| document.getElementById("qaFileNameDisplay").textContent = ""; | |
| // Reset file input | |
| const fileInput = document.getElementById("file"); | |
| const fileNameSpan = document.getElementById("fileName"); | |
| fileInput.value = ""; | |
| fileNameSpan.textContent = "์ ํ๋ ํ์ผ ์์"; | |
| document.getElementById("uploadButton").classList.add("hidden"); | |
| }); | |
| }); | |