Spaces:
Paused
Paused
Update static/index.html
Browse files- static/index.html +164 -165
static/index.html
CHANGED
|
@@ -31,182 +31,181 @@
|
|
| 31 |
|
| 32 |
|
| 33 |
<script>
|
|
|
|
| 34 |
document.addEventListener("DOMContentLoaded", function() {
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
xhr.onloadstart = function() {
|
| 78 |
-
// Start simulating progress during backend processing
|
| 79 |
-
simulateBackendProcessingProgress();
|
| 80 |
-
};
|
| 81 |
-
|
| 82 |
-
xhr.onload = function() {
|
| 83 |
-
clearInterval(simulatedProgressInterval); // Stop simulation
|
| 84 |
-
if (xhr.status === 200) {
|
| 85 |
-
const resultBlob = xhr.response;
|
| 86 |
-
const resultURL = URL.createObjectURL(resultBlob);
|
| 87 |
-
|
| 88 |
-
const originalURL = URL.createObjectURL(file);
|
| 89 |
-
|
| 90 |
-
// Debugging: Check the URLs and Blob objects
|
| 91 |
-
console.log("Original URL:", originalURL);
|
| 92 |
-
console.log("Result URL:", resultURL);
|
| 93 |
-
console.log("Result Blob:", resultBlob);
|
| 94 |
-
|
| 95 |
-
resultDiv.innerHTML = `
|
| 96 |
-
<h2>Result</h2>
|
| 97 |
-
<div class="result-images">
|
| 98 |
-
<img src="${originalURL}" alt="Original Image" class="result-image">
|
| 99 |
-
<span class="arrow">↓</span>
|
| 100 |
-
<img src="${resultURL}" alt="Result Image" class="result-image">
|
| 101 |
-
</div>
|
| 102 |
-
`;
|
| 103 |
-
|
| 104 |
-
// Create and append the download button
|
| 105 |
-
const downloadButton = document.createElement('a');
|
| 106 |
-
downloadButton.href = resultURL;
|
| 107 |
-
downloadButton.download = 'result.jpg';
|
| 108 |
-
downloadButton.textContent = 'Download Result';
|
| 109 |
-
downloadButton.className = 'btn-download';
|
| 110 |
-
resultDiv.appendChild(downloadButton);
|
| 111 |
-
|
| 112 |
-
updateProgressBar(100);
|
| 113 |
-
} else {
|
| 114 |
-
resultDiv.innerHTML = `<p class="error-message">Error: ${xhr.statusText}</p>`;
|
| 115 |
-
updateProgressBar(0);
|
| 116 |
-
}
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
}
|
| 161 |
-
// Set the canvas dimensions
|
| 162 |
-
canvas.width = width;
|
| 163 |
-
canvas.height = height;
|
| 164 |
-
// Draw the image on the canvas with the new dimensions
|
| 165 |
-
ctx.drawImage(img, 0, 0, width, height);
|
| 166 |
-
// Convert canvas content to a blob
|
| 167 |
-
canvas.toBlob((blob) => {
|
| 168 |
-
resolve(blob);
|
| 169 |
-
}, 'image/jpeg', 0.7); // Adjust quality as needed (0.7 is 70% quality)
|
| 170 |
}
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
}
|
| 204 |
-
}
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
<style>
|
| 211 |
|
| 212 |
.ai-tool-container body{
|
|
@@ -376,4 +375,4 @@
|
|
| 376 |
background-color: #218838;
|
| 377 |
}
|
| 378 |
</style>
|
| 379 |
-
</div>
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
<script>
|
| 34 |
+
|
| 35 |
document.addEventListener("DOMContentLoaded", function() {
|
| 36 |
+
const form = document.getElementById("remakeai-form");
|
| 37 |
+
const fileInput = document.getElementById('file');
|
| 38 |
+
const fileNameSpan = document.getElementById('file-name');
|
| 39 |
+
const progressBar = document.getElementById('progress-bar');
|
| 40 |
+
const progressContainer = document.querySelector('.progress-container');
|
| 41 |
+
const resultDiv = document.querySelector(".result");
|
| 42 |
+
|
| 43 |
+
let simulatedProgressInterval;
|
| 44 |
+
let simulatedProgress = 0;
|
| 45 |
+
|
| 46 |
+
fileInput.addEventListener('change', function() {
|
| 47 |
+
fileNameSpan.textContent = this.files[0].name;
|
| 48 |
+
});
|
| 49 |
|
| 50 |
+
form.addEventListener("submit", async function(event) {
|
| 51 |
+
event.preventDefault();
|
| 52 |
|
| 53 |
+
const file = fileInput.files[0];
|
| 54 |
+
const compressedFile = await compressImage(file);
|
| 55 |
|
| 56 |
+
const formData = new FormData();
|
| 57 |
+
formData.append('file', compressedFile, file.name);
|
| 58 |
+
|
| 59 |
+
// Reset and show the progress bar
|
| 60 |
+
progressBar.style.width = '0%';
|
| 61 |
+
progressContainer.style.display = 'block';
|
| 62 |
+
simulatedProgress = 0;
|
| 63 |
+
|
| 64 |
+
// Clear previous result
|
| 65 |
+
resultDiv.innerHTML = '';
|
| 66 |
+
|
| 67 |
+
const xhr = new XMLHttpRequest();
|
| 68 |
+
xhr.open("POST", "/upload/", true);
|
| 69 |
+
xhr.responseType = 'json'; // Ensure the response is treated as JSON
|
| 70 |
+
|
| 71 |
+
xhr.upload.onprogress = function(event) {
|
| 72 |
+
if (event.lengthComputable) {
|
| 73 |
+
const percentComplete = (event.loaded / event.total) * 100;
|
| 74 |
+
updateProgressBar(percentComplete);
|
| 75 |
+
}
|
| 76 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
xhr.onloadstart = function() {
|
| 79 |
+
// Start simulating progress during backend processing
|
| 80 |
+
simulateBackendProcessingProgress();
|
| 81 |
+
};
|
| 82 |
|
| 83 |
+
xhr.onload = function() {
|
| 84 |
+
clearInterval(simulatedProgressInterval); // Stop simulation
|
| 85 |
+
if (xhr.status === 200) {
|
| 86 |
+
const response = xhr.response;
|
| 87 |
|
| 88 |
+
if (response.error) {
|
| 89 |
+
resultDiv.innerHTML = `<p class="error-message">${response.error}</p>`;
|
| 90 |
+
} else {
|
| 91 |
+
const originalURL = URL.createObjectURL(file);
|
| 92 |
+
const sketchImageBase64 = response.sketch_image_base64;
|
| 93 |
+
|
| 94 |
+
resultDiv.innerHTML = `
|
| 95 |
+
<h2>Result</h2>
|
| 96 |
+
<div class="result-images">
|
| 97 |
+
<img src="${originalURL}" alt="Original Image" class="result-image">
|
| 98 |
+
<span class="arrow">↓</span>
|
| 99 |
+
<img src="${sketchImageBase64}" alt="Sketch Image" class="result-image">
|
| 100 |
+
</div>
|
| 101 |
+
`;
|
| 102 |
+
|
| 103 |
+
// Create and append the download button
|
| 104 |
+
const downloadButton = document.createElement('a');
|
| 105 |
+
downloadButton.href = sketchImageBase64;
|
| 106 |
+
downloadButton.download = 'result.jpg';
|
| 107 |
+
downloadButton.textContent = 'Download Result';
|
| 108 |
+
downloadButton.className = 'btn-download';
|
| 109 |
+
resultDiv.appendChild(downloadButton);
|
| 110 |
+
|
| 111 |
+
updateProgressBar(100);
|
| 112 |
+
}
|
| 113 |
+
} else {
|
| 114 |
+
resultDiv.innerHTML = `<p class="error-message">Error: ${xhr.statusText}</p>`;
|
| 115 |
+
updateProgressBar(0);
|
| 116 |
+
}
|
| 117 |
|
| 118 |
+
setTimeout(() => {
|
| 119 |
+
progressContainer.style.display = 'none';
|
| 120 |
+
}, 1000);
|
| 121 |
+
};
|
| 122 |
|
| 123 |
+
xhr.onerror = function() {
|
| 124 |
+
clearInterval(simulatedProgressInterval); // Stop simulation
|
| 125 |
+
resultDiv.innerHTML = `<p class="error-message">Error: Network Error</p>`;
|
| 126 |
+
updateProgressBar(0);
|
| 127 |
+
|
| 128 |
+
setTimeout(() => {
|
| 129 |
+
progressContainer.style.display = 'none';
|
| 130 |
+
}, 1000);
|
| 131 |
+
};
|
| 132 |
+
|
| 133 |
+
xhr.send(formData);
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
async function compressImage(file) {
|
| 137 |
+
return new Promise((resolve, reject) => {
|
| 138 |
+
const reader = new FileReader();
|
| 139 |
+
reader.onload = function(event) {
|
| 140 |
+
const img = new Image();
|
| 141 |
+
img.src = event.target.result;
|
| 142 |
+
img.onload = function() {
|
| 143 |
+
const canvas = document.createElement('canvas');
|
| 144 |
+
const ctx = canvas.getContext('2d');
|
| 145 |
+
// Calculate the new dimensions to resize the image while maintaining aspect ratio
|
| 146 |
+
const maxWidth = 1000;
|
| 147 |
+
const maxHeight = 1000;
|
| 148 |
+
let width = img.width;
|
| 149 |
+
let height = img.height;
|
| 150 |
+
if (width > height) {
|
| 151 |
+
if (width > maxWidth) {
|
| 152 |
+
height *= maxWidth / width;
|
| 153 |
+
width = maxWidth;
|
| 154 |
+
}
|
| 155 |
+
} else {
|
| 156 |
+
if (height > maxHeight) {
|
| 157 |
+
width *= maxHeight / height;
|
| 158 |
+
height = maxHeight;
|
| 159 |
+
}
|
| 160 |
}
|
| 161 |
+
// Set the canvas dimensions
|
| 162 |
+
canvas.width = width;
|
| 163 |
+
canvas.height = height;
|
| 164 |
+
// Draw the image on the canvas with the new dimensions
|
| 165 |
+
ctx.drawImage(img, 0, 0, width, height);
|
| 166 |
+
// Convert canvas content to a blob
|
| 167 |
+
canvas.toBlob((blob) => {
|
| 168 |
+
resolve(blob);
|
| 169 |
+
}, 'image/jpeg', 0.7); // Adjust quality as needed (0.7 is 70% quality)
|
| 170 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
}
|
| 172 |
+
// Read the file as data URL
|
| 173 |
+
reader.readAsDataURL(file);
|
| 174 |
+
});
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
function updateProgressBar(percentComplete) {
|
| 178 |
+
progressBar.style.width = percentComplete + '%';
|
| 179 |
+
updateProgressBarColor(percentComplete);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
function updateProgressBarColor(percentComplete) {
|
| 183 |
+
const startColor = "#ff0000"; // Red
|
| 184 |
+
const endColor = "#0056b3"; // Blue
|
| 185 |
+
const currentColor = interpolateColor(startColor, endColor, percentComplete / 100);
|
| 186 |
+
progressBar.style.backgroundColor = currentColor;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
function interpolateColor(color1, color2, factor) {
|
| 190 |
+
const result = color1.slice(1).match(/.{2}/g).map((hex, i) => {
|
| 191 |
+
return Math.round(parseInt(hex, 16) * (1 - factor) + parseInt(color2.slice(1).match(/.{2}/g)[i], 16) * factor);
|
| 192 |
+
});
|
| 193 |
+
return `#${result.map(val => val.toString(16).padStart(2, '0')).join('')}`;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
function simulateBackendProcessingProgress() {
|
| 197 |
+
simulatedProgressInterval = setInterval(() => {
|
| 198 |
+
simulatedProgress += 1; // Increment progress by 1%
|
| 199 |
+
if (simulatedProgress < 90) { // Cap the simulated progress at 90%
|
| 200 |
+
updateProgressBar(simulatedProgress);
|
| 201 |
+
} else {
|
| 202 |
+
clearInterval(simulatedProgressInterval); // Stop simulation at 90%
|
| 203 |
+
}
|
| 204 |
+
}, 200); // Update every 200ms
|
| 205 |
+
}
|
| 206 |
+
});
|
| 207 |
+
</script>
|
| 208 |
+
|
|
|
|
|
|
|
| 209 |
<style>
|
| 210 |
|
| 211 |
.ai-tool-container body{
|
|
|
|
| 375 |
background-color: #218838;
|
| 376 |
}
|
| 377 |
</style>
|
| 378 |
+
</div>
|