soiz1 commited on
Commit
5edd87d
·
verified ·
1 Parent(s): 0c3285b

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +128 -39
templates/index.html CHANGED
@@ -3,11 +3,11 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>DIS Image Background Removal</title>
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
- max-width: 900px;
11
  margin: 0 auto;
12
  padding: 20px;
13
  line-height: 1.6;
@@ -23,35 +23,41 @@
23
  }
24
  .upload-section {
25
  border: 2px dashed #ccc;
26
- padding: 20px;
27
  text-align: center;
28
- border-radius: 5px;
 
29
  }
30
  .results {
31
- display: flex;
32
- flex-wrap: wrap;
33
  gap: 20px;
34
- justify-content: center;
35
  }
36
- .result-item {
37
- display: flex;
38
- flex-direction: column;
39
- align-items: center;
 
40
  }
41
- .result-item img {
42
- max-width: 300px;
 
 
 
 
43
  max-height: 300px;
44
- border: 1px solid #ddd;
45
  margin-bottom: 10px;
46
  }
47
  button {
48
  background-color: #4CAF50;
49
  color: white;
50
- padding: 10px 15px;
51
  border: none;
52
  border-radius: 4px;
53
  cursor: pointer;
54
  font-size: 16px;
 
55
  }
56
  button:hover {
57
  background-color: #45a049;
@@ -60,43 +66,98 @@
60
  display: none;
61
  text-align: center;
62
  margin: 20px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
  .info {
65
  background-color: #f8f9fa;
66
- padding: 15px;
67
- border-radius: 5px;
68
- margin-top: 20px;
69
  }
70
- .error {
71
- color: red;
72
- margin: 10px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  }
74
  </style>
75
  </head>
76
  <body>
77
- <h1>Highly Accurate Dichotomous Image Segmentation</h1>
78
-
79
  <div class="container">
 
 
80
  <div class="upload-section">
81
  <h2>Upload Image</h2>
82
- <input type="file" id="imageInput" accept="image/*">
 
 
83
  <button onclick="processImage()">Remove Background</button>
84
- <div id="loading">Processing... Please wait...</div>
 
85
  <div id="error" class="error"></div>
 
 
 
 
 
86
  </div>
87
 
88
- <div class="results" id="results">
89
- <!-- Results will be displayed here -->
 
 
 
90
  </div>
91
 
92
  <div class="info">
93
  <h3>About this service</h3>
94
- <p>This is an implementation of DIS, a model that can remove the background from a given image.</p>
95
  <p>GitHub: <a href="https://github.com/xuebinqin/DIS" target="_blank">https://github.com/xuebinqin/DIS</a></p>
 
 
 
 
96
  </div>
97
  </div>
98
-
99
  <script>
 
 
 
 
 
 
 
 
 
100
  function processImage() {
101
  const fileInput = document.getElementById('imageInput');
102
  const file = fileInput.files[0];
@@ -109,12 +170,14 @@
109
  }
110
 
111
  const loading = document.getElementById('loading');
 
112
  loading.style.display = 'block';
 
113
 
114
  const formData = new FormData();
115
  formData.append('image', file);
116
 
117
- fetch('/api/remove_bg', {
118
  method: 'POST',
119
  body: formData
120
  })
@@ -134,21 +197,24 @@
134
 
135
  const resultsDiv = document.getElementById('results');
136
  resultsDiv.innerHTML = `
137
- <div class="result-item">
138
  <h3>Original Image</h3>
139
- <img src="/uploads/${data.original_filename}" alt="Original Image">
 
140
  </div>
141
- <div class="result-item">
142
  <h3>Background Removed</h3>
143
- <img src="${data.rgba_image}" alt="Background Removed">
144
- <a href="${data.rgba_image}" download="bg_removed_${data.original_filename}">Download</a>
145
  </div>
146
- <div class="result-item">
147
- <h3>Mask</h3>
148
- <img src="${data.mask_image}" alt="Mask">
149
- <a href="${data.mask_image}" download="mask_${data.original_filename}">Download</a>
150
  </div>
151
  `;
 
 
152
  })
153
  .catch(error => {
154
  loading.style.display = 'none';
@@ -156,6 +222,29 @@
156
  errorDiv.textContent = error.error || 'An error occurred while processing the image';
157
  });
158
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  </script>
160
  </body>
161
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Highly Accurate Dichotomous Image Segmentation</title>
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
+ max-width: 1000px;
11
  margin: 0 auto;
12
  padding: 20px;
13
  line-height: 1.6;
 
23
  }
24
  .upload-section {
25
  border: 2px dashed #ccc;
26
+ padding: 30px;
27
  text-align: center;
28
+ border-radius: 8px;
29
+ background: #f9f9f9;
30
  }
31
  .results {
32
+ display: grid;
33
+ grid-template-columns: repeat(3, 1fr);
34
  gap: 20px;
35
+ margin-top: 30px;
36
  }
37
+ .result-box {
38
+ border: 1px solid #ddd;
39
+ padding: 15px;
40
+ border-radius: 5px;
41
+ text-align: center;
42
  }
43
+ .result-box h3 {
44
+ margin-top: 0;
45
+ }
46
+ .result-img {
47
+ max-width: 100%;
48
+ height: auto;
49
  max-height: 300px;
 
50
  margin-bottom: 10px;
51
  }
52
  button {
53
  background-color: #4CAF50;
54
  color: white;
55
+ padding: 12px 20px;
56
  border: none;
57
  border-radius: 4px;
58
  cursor: pointer;
59
  font-size: 16px;
60
+ transition: background-color 0.3s;
61
  }
62
  button:hover {
63
  background-color: #45a049;
 
66
  display: none;
67
  text-align: center;
68
  margin: 20px 0;
69
+ font-size: 18px;
70
+ }
71
+ .error {
72
+ color: #d32f2f;
73
+ margin: 10px 0;
74
+ text-align: center;
75
+ }
76
+ .download-btn {
77
+ display: inline-block;
78
+ background: #2196F3;
79
+ color: white;
80
+ padding: 8px 15px;
81
+ text-decoration: none;
82
+ border-radius: 4px;
83
+ margin-top: 5px;
84
+ }
85
+ .download-btn:hover {
86
+ background: #0b7dda;
87
  }
88
  .info {
89
  background-color: #f8f9fa;
90
+ padding: 20px;
91
+ border-radius: 8px;
92
+ margin-top: 30px;
93
  }
94
+ .example-images {
95
+ display: flex;
96
+ gap: 15px;
97
+ margin: 20px 0;
98
+ justify-content: center;
99
+ }
100
+ .example-img {
101
+ width: 150px;
102
+ height: 150px;
103
+ object-fit: cover;
104
+ cursor: pointer;
105
+ border: 2px solid transparent;
106
+ border-radius: 4px;
107
+ }
108
+ .example-img:hover {
109
+ border-color: #4CAF50;
110
  }
111
  </style>
112
  </head>
113
  <body>
 
 
114
  <div class="container">
115
+ <h1>Highly Accurate Dichotomous Image Segmentation</h1>
116
+
117
  <div class="upload-section">
118
  <h2>Upload Image</h2>
119
+ <input type="file" id="imageInput" accept="image/*" style="display: none;">
120
+ <button onclick="document.getElementById('imageInput').click()">Select Image</button>
121
+ <p id="fileName" style="margin: 10px 0;"></p>
122
  <button onclick="processImage()">Remove Background</button>
123
+
124
+ <div id="loading">Processing your image... Please wait...</div>
125
  <div id="error" class="error"></div>
126
+
127
+ <div class="example-images">
128
+ <img src="/examples/robot.png" class="example-img" onclick="loadExample('robot.png')" alt="Robot Example">
129
+ <img src="/examples/ship.png" class="example-img" onclick="loadExample('ship.png')" alt="Ship Example">
130
+ </div>
131
  </div>
132
 
133
+ <div id="resultsContainer" style="display: none;">
134
+ <h2 style="text-align: center;">Results</h2>
135
+ <div class="results" id="results">
136
+ <!-- Results will be inserted here -->
137
+ </div>
138
  </div>
139
 
140
  <div class="info">
141
  <h3>About this service</h3>
142
+ <p>This is an implementation of DIS, a model that can remove the background from a given image with high accuracy.</p>
143
  <p>GitHub: <a href="https://github.com/xuebinqin/DIS" target="_blank">https://github.com/xuebinqin/DIS</a></p>
144
+ <p>Telegram bot: <a href="https://t.me/restoration_photo_bot" target="_blank">https://t.me/restoration_photo_bot</a></p>
145
+ <div style="text-align: center; margin-top: 15px;">
146
+ <img src="https://visitor-badge.glitch.me/badge?page_id=dis_image_segmentation" alt="visitor badge">
147
+ </div>
148
  </div>
149
  </div>
150
+
151
  <script>
152
+ // Update file name display
153
+ document.getElementById('imageInput').addEventListener('change', function(e) {
154
+ const fileName = e.target.files[0] ? e.target.files[0].name : 'No file selected';
155
+ document.getElementById('fileName').textContent = `Selected: ${fileName}`;
156
+ document.getElementById('error').textContent = '';
157
+ document.getElementById('resultsContainer').style.display = 'none';
158
+ });
159
+
160
+ // Process image
161
  function processImage() {
162
  const fileInput = document.getElementById('imageInput');
163
  const file = fileInput.files[0];
 
170
  }
171
 
172
  const loading = document.getElementById('loading');
173
+ const resultsContainer = document.getElementById('resultsContainer');
174
  loading.style.display = 'block';
175
+ resultsContainer.style.display = 'none';
176
 
177
  const formData = new FormData();
178
  formData.append('image', file);
179
 
180
+ fetch('/api/process', {
181
  method: 'POST',
182
  body: formData
183
  })
 
197
 
198
  const resultsDiv = document.getElementById('results');
199
  resultsDiv.innerHTML = `
200
+ <div class="result-box">
201
  <h3>Original Image</h3>
202
+ <img src="${data.original}" class="result-img" alt="Original Image">
203
+ <a href="${data.original}" class="download-btn" download="${data.filename}">Download</a>
204
  </div>
205
+ <div class="result-box">
206
  <h3>Background Removed</h3>
207
+ <img src="${data.rgba}" class="result-img" alt="Background Removed">
208
+ <a href="${data.rgba}" class="download-btn" download="no_bg_${data.filename}">Download</a>
209
  </div>
210
+ <div class="result-box">
211
+ <h3>Segmentation Mask</h3>
212
+ <img src="${data.mask}" class="result-img" alt="Segmentation Mask">
213
+ <a href="${data.mask}" class="download-btn" download="mask_${data.filename}">Download</a>
214
  </div>
215
  `;
216
+
217
+ resultsContainer.style.display = 'block';
218
  })
219
  .catch(error => {
220
  loading.style.display = 'none';
 
222
  errorDiv.textContent = error.error || 'An error occurred while processing the image';
223
  });
224
  }
225
+
226
+ // Load example image
227
+ function loadExample(filename) {
228
+ fetch(`/examples/${filename}`)
229
+ .then(response => response.blob())
230
+ .then(blob => {
231
+ const file = new File([blob], filename, { type: blob.type });
232
+ const dataTransfer = new DataTransfer();
233
+ dataTransfer.items.add(file);
234
+ document.getElementById('imageInput').files = dataTransfer.files;
235
+
236
+ // Trigger file name display
237
+ const event = new Event('change');
238
+ document.getElementById('imageInput').dispatchEvent(event);
239
+
240
+ // Process the example immediately
241
+ processImage();
242
+ })
243
+ .catch(error => {
244
+ console.error('Error loading example:', error);
245
+ document.getElementById('error').textContent = 'Failed to load example image';
246
+ });
247
+ }
248
  </script>
249
  </body>
250
  </html>