Ashrafb commited on
Commit
400921b
1 Parent(s): c1f7202

Create index2.html

Browse files
Files changed (1) hide show
  1. static/index2.html +79 -0
static/index2.html ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function uploadImage() {
2
+ const fileInput = document.getElementById('image');
3
+ const versionInput = document.getElementById('version');
4
+ const scaleInput = document.getElementById('scale');
5
+
6
+ // Check if the file input is empty
7
+ if (!fileInput.files[0]) {
8
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Please upload an image.</p>`;
9
+ return;
10
+ }
11
+
12
+ // Check if the file size is above 1500 KB
13
+ if (fileInput.files[0].size > 1500 * 1024) {
14
+ // Display loading spinner and estimated time
15
+ const loadingSpinner = document.getElementById('loadingSpinner');
16
+ loadingSpinner.style.display = 'block';
17
+ const estimatedTime = document.getElementById('estimatedTime');
18
+ estimatedTime.style.display = 'block';
19
+
20
+ // Hide loading spinner and estimated time after 30 seconds
21
+ setTimeout(() => {
22
+ loadingSpinner.style.display = 'none';
23
+ estimatedTime.style.display = 'none';
24
+
25
+ // Display uploaded image after 30 seconds
26
+ const reader = new FileReader();
27
+ reader.onload = function(e) {
28
+ const resultContainer = document.getElementById('resultContainer');
29
+ const uploadedImage = document.createElement('img');
30
+ uploadedImage.src = e.target.result;
31
+ uploadedImage.style.maxWidth = '100%'; // Adjust this value as needed
32
+ uploadedImage.style.maxHeight = '100%'; // Adjust this value as needed
33
+ resultContainer.innerHTML = ''; // Clear previous content
34
+ resultContainer.appendChild(uploadedImage);
35
+ };
36
+ reader.readAsDataURL(fileInput.files[0]);
37
+ }, 30000);
38
+
39
+ return;
40
+ }
41
+
42
+ // Clear the result container
43
+ document.getElementById('resultContainer').innerHTML = "";
44
+
45
+ const formData = new FormData();
46
+ formData.append('file', fileInput.files[0]);
47
+ formData.append('version', versionInput.value);
48
+ formData.append('scale', scaleInput.value);
49
+
50
+ // Display loading spinner
51
+ const loadingSpinner = document.getElementById('loadingSpinner');
52
+ loadingSpinner.style.display = 'block';
53
+ const estimatedTime = document.getElementById('estimatedTime');
54
+ estimatedTime.style.display = 'block';
55
+ try {
56
+ const response = await fetch('https://ashrafb-furdockgr1.hf.space/upload/', {
57
+ method: 'POST',
58
+ body: formData
59
+ });
60
+
61
+ // Hide loading spinner
62
+ loadingSpinner.style.display = 'none';
63
+ estimatedTime.style.display = 'none';
64
+ if (response.ok) {
65
+ const resultContainer = document.getElementById('resultContainer');
66
+ const data = await response.json();
67
+ const sketchImage = document.createElement('img');
68
+ sketchImage.style.maxWidth = '100%'; // Adjust this value as needed
69
+ sketchImage.style.maxHeight = '100%'; // Adjust this value as needed
70
+ sketchImage.src = data.sketch_image_base64;
71
+ resultContainer.appendChild(sketchImage);
72
+ } else {
73
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
74
+ }
75
+ } catch (error) {
76
+ console.error('Error:', error);
77
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
78
+ }
79
+ }