From a833cb5699168fb20797e29c8fd2f7ac476d3a81 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 8 Dec 2024 22:59:06 +0000 Subject: [PATCH] progress indicator for upload processing. demo.html page new file: demo.html modified: uncloseai.js --- demo.html | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ uncloseai.js | 47 +++++++++++++++++++++++++++---- 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 demo.html diff --git a/demo.html b/demo.html new file mode 100644 index 0000000..d648ae7 --- /dev/null +++ b/demo.html @@ -0,0 +1,79 @@ + + + + + + + + + Demo Free LLM & Text To Speech Artificial Intelligence Service | ai.unturf.com + + + + + + + + + + + + + + + + + + + + + +
+
+

unturf.

+

Welcome to ai.unturf.com - Free LLM & Text To Speech Artificial Intelligence Service +

+ +
+ +
+

Demo!

+ +
+
+
+
+
+ + +
+ +
+ + + + + + diff --git a/uncloseai.js b/uncloseai.js index 7cd6bc4..985aa75 100644 --- a/uncloseai.js +++ b/uncloseai.js @@ -565,7 +565,7 @@ function addReadPageButton() { // New Function: Add File Picker and Upload Button function addFileUploadButton() { - const chatContainer = document.getElementById('chat-container'); + const userInputContainer = document.getElementById('user-input').parentNode; // Create a container for the upload elements const uploadContainer = document.createElement('div'); @@ -586,11 +586,38 @@ function addFileUploadButton() { uploadContainer.appendChild(fileInput); uploadContainer.appendChild(uploadButton); - // Append the upload container to the chat container - chatContainer.parentNode.insertBefore(uploadContainer, chatContainer); + // Append the upload container below the user input + userInputContainer.parentNode.insertBefore(uploadContainer, userInputContainer.nextSibling); } -// New Function: Handle File Upload +// Function to show progress indicator +function showProgressIndicator(message) { + let progressIndicator = document.getElementById('progress-indicator'); + if (!progressIndicator) { + progressIndicator = document.createElement('div'); + progressIndicator.id = 'progress-indicator'; + progressIndicator.style.position = 'fixed'; + progressIndicator.style.top = '10px'; + progressIndicator.style.right = '10px'; + progressIndicator.style.padding = '10px'; + progressIndicator.style.background = 'rgba(0,0,0,0.8)'; + progressIndicator.style.color = 'white'; + progressIndicator.style.borderRadius = '5px'; + progressIndicator.style.zIndex = '1000'; + document.body.appendChild(progressIndicator); + } + progressIndicator.textContent = message; +} + +// Function to hide progress indicator +function hideProgressIndicator() { + const progressIndicator = document.getElementById('progress-indicator'); + if (progressIndicator) { + progressIndicator.remove(); + } +} + +// Updated Function: Handle File Upload with Progress Indicator async function handleFileUpload() { const fileInput = document.getElementById('file-input'); const files = fileInput.files; @@ -603,21 +630,31 @@ async function handleFileUpload() { const file = files[0]; try { + // Show progress indicator for upload + showProgressIndicator('Uploading & Processing file...'); + // Send file to MegaFarce endpoint const response = await uploadFile(file); + // Show progress indicator for processing + showProgressIndicator('Processing file...'); + // Integrate response into Chat DOM and chatHistory await integrateMegafarceResponse(response); + // Hide progress indicator after completion + hideProgressIndicator(); + // Clear the file input after successful upload fileInput.value = ''; } catch (error) { console.error('File upload error:', error); alert('Failed to upload the file.'); + hideProgressIndicator(); } } -// New Function: Upload File to MegaFarce +// New Function: Upload File to MegaFarce with Progress Indicator async function uploadFile(file) { const formData = new FormData(); formData.append('file', file);