Ashrafb commited on
Commit
b8b172f
·
verified ·
1 Parent(s): 814da2f

Update AB/index.html

Browse files
Files changed (1) hide show
  1. AB/index.html +58 -92
AB/index.html CHANGED
@@ -219,30 +219,32 @@ h1 {
219
  </style>
220
  </head>
221
  <body>
222
- <h1>Aiconvert.online </h1>
223
- <form id="uploadForm" action="/upload/" method="post" enctype="multipart/form-data">
224
- <label for="sourceFile" class="uploadLabel">Choose image </label>
225
- <input type="file" id="image_file" name="image_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')"><br>
226
- <div id="sourceImageContainer">
227
- <img id="sourceImage">
228
- </div><br>
229
- <button type="button" onclick="uploadFile()">Generate </button> <!-- Changed to type="button" and added onclick handler -->
 
 
 
 
 
 
 
 
 
 
 
 
230
  </form>
231
  <div id="resultImage">
232
- <div id="estimatedTime" style="display: none;">Estimated time: 120s</div>
233
- <div id="loadingSpinner" style="display: none;">
234
- <!-- Replace this with your loading spinner HTML/CSS -->
235
- </div>
236
- <div id="resultContainer">
237
-
238
-
239
-
240
-
241
- <a id="download-link" href="#" download="colorized_image.jpg" style="display:none;">Download Colorized Image</a>
242
- </div>
243
  </div>
244
  <script>
245
- function previewImage(event, imageId) {
246
  const fileInput = event.target;
247
  const file = fileInput.files[0];
248
  const reader = new FileReader();
@@ -255,80 +257,44 @@ h1 {
255
  reader.readAsDataURL(file);
256
  }
257
 
258
-
259
- // Function to display the processed image
260
- function displayResultImage(url) {
261
- const resultContainer = document.getElementById('resultContainer');
262
- // Create an image element
263
- const img = document.createElement('img');
264
- // Set the source attribute to the processed image URL
265
- img.src = url;
266
- // Append the image element to the result container
267
- resultContainer.appendChild(img);
268
- }
269
-
270
-
271
  async function uploadFile() {
272
  const image_fileInput = document.getElementById('image_file');
273
- const resultContainer = document.getElementById('resultContainer');
274
-
275
-
276
-
277
- // Check if both source and destination file inputs are empty
278
- if (!image_file.files[0] ) {
279
- // Update the result container with the error message
280
- resultContainer.innerHTML = "<p>Please upload an image.</p>";
281
- return;
282
- }
283
-
284
- // Clear the result container if both images are uploaded
285
- resultContainer.innerHTML = "";
286
-
287
- const formData = new FormData();
288
- const fileInput = document.querySelector('input[type="file"]');
289
- formData.append('image_file', image_file.files[0]);
290
-
291
- try {
292
- // Display loading spinner
293
- const loadingSpinner = document.getElementById('loadingSpinner');
294
- loadingSpinner.style.display = 'block';
295
- const estimatedTime = document.getElementById('estimatedTime');
296
- estimatedTime.style.display = 'block';
297
-
298
- const response = await fetch('/upload/', {
299
- method: 'POST',
300
- body: formData
301
- });
302
- if (response.ok) {
303
- // If successful response, display the result image
304
- const blob = await response.blob();
305
- const url = URL.createObjectURL(blob); // Retrieve the URL of the processed image
306
- displayResultImage(url); // Pass the URL to the displayResultImage function
307
- } else {
308
- // If server error, display the error message
309
- const errorMessage = await response.text();
310
- resultContainer.innerHTML = `<p>Oops! Something went wrong. Please try again later. </p>`;
311
- }
312
-
313
- // Hide loading spinner after result (or error message) is displayed
314
- loadingSpinner.style.display = 'none';
315
- estimatedTime.style.display = 'none';
316
- } catch (error) {
317
- console.error('Error swapping faces:', error);
318
- // Hide loading spinner if there's an error
319
- const loadingSpinner = document.getElementById('loadingSpinner');
320
- loadingSpinner.style.display = 'none';
321
- estimatedTime.style.display = 'none';
322
- }
323
- }
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
  </script>
332
  </body>
333
  </html>
334
-
 
219
  </style>
220
  </head>
221
  <body>
222
+ <h1>Aiconvert.online</h1>
223
+ <form id="uploadForm" action="/upload/" method="post" enctype="multipart/form-data">
224
+ <label for="sourceFile" class="uploadLabel">Choose image</label>
225
+ <input type="file" id="image_file" name="image_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')"><br>
226
+ <div id="sourceImageContainer">
227
+ <img id="sourceImage">
228
+ </div><br>
229
+ <label for="top">Top:</label>
230
+ <input type="number" id="top" name="top" required><br>
231
+
232
+ <label for="bottom">Bottom:</label>
233
+ <input type="number" id="bottom" name="bottom" required><br>
234
+
235
+ <label for="left">Left:</label>
236
+ <input type="number" id="left" name="left" required><br>
237
+
238
+ <label for="right">Right:</label>
239
+ <input type="number" id="right" name="right" required><br>
240
+
241
+ <button type="button" onclick="uploadFile()">Generate</button>
242
  </form>
243
  <div id="resultImage">
244
+ <!-- Add the result image container and loading spinner here -->
 
 
 
 
 
 
 
 
 
 
245
  </div>
246
  <script>
247
+ function previewImage(event, imageId) {
248
  const fileInput = event.target;
249
  const file = fileInput.files[0];
250
  const reader = new FileReader();
 
257
  reader.readAsDataURL(file);
258
  }
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  async function uploadFile() {
261
  const image_fileInput = document.getElementById('image_file');
262
+ const top = document.getElementById('top').value;
263
+ const bottom = document.getElementById('bottom').value;
264
+ const left = document.getElementById('left').value;
265
+ const right = document.getElementById('right').value;
266
+ const formData = new FormData();
267
+
268
+ // Append the uploaded image and other form data
269
+ formData.append('image_file', image_fileInput.files[0]);
270
+ formData.append('top', top);
271
+ formData.append('bottom', bottom);
272
+ formData.append('left', left);
273
+ formData.append('right', right);
274
+
275
+ try {
276
+ const response = await fetch('/upload/', {
277
+ method: 'POST',
278
+ body: formData
279
+ });
280
+
281
+ if (response.ok) {
282
+ // If successful response, display the result image
283
+ const resultImageContainer = document.getElementById('resultImage');
284
+ const resultData = await response.json();
285
+ const resultImage = new Image();
286
+ resultImage.src = 'data:image/jpeg;base64,' + resultData.result_image;
287
+ resultImageContainer.innerHTML = '';
288
+ resultImageContainer.appendChild(resultImage);
289
+ } else {
290
+ // If server error, display the error message
291
+ const errorMessage = await response.text();
292
+ console.error('Error:', errorMessage);
293
+ }
294
+ } catch (error) {
295
+ console.error('Error:', error);
296
+ }
297
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  </script>
299
  </body>
300
  </html>