-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
315 lines (248 loc) · 12.3 KB
/
main.html
File metadata and controls
315 lines (248 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
162
163
164
165
166
167
168
169
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!DOCTYPE html>
<html>
<head>
<title>XAI Microservices Interface</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
/* Custom styles */
body {
font-family: Arial, sans-serif;
}
.hidden {
display: none;
}
.arrow {
cursor: pointer;
}
.loader {
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center">XAI Microservices Interface</h1>
<h3>Welcome, <span id="userRole"></span>!</h3>
<h2>
<span class="arrow" onclick="toggleSection('occlusionForm')">▶</span>
xAI Explanations
</h2>
<form id="occlusionForm" enctype="multipart/form-data">
<div class="form-group">
<label for="occlusionImageFile">Image File:</label>
<input type="file" id="occlusionImageFile" name="file" accept=".jpg,.jpeg,.png" required>
</div>
<div class="form-group">
<label for="occlusionClassLabel">Class Label:</label>
<select id="occlusionClassLabel" required class="form-control">
<option value="cardboard">Cardboard</option>
<option value="glass">Glass</option>
<option value="metal">Metal</option>
<option value="paper">Paper</option>
<option value="plastic">Plastic</option>
<option value="trash">Trash</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Explain</button>
<br><br>
<div id="LoadingExplanations"></div>
<div class="section" id="User_shappredictionResult">
<!-- <h3>Prediction Result</h3> -->
<div id="shappredictionResult"></div>
</div>
<div class="section" id="User_limeImageResult">
<!-- <h3>LIME Image Result</h3> -->
<div id="limeImageResult"></div>
</div>
<div class="section" id="User_limetop_T">
<!-- <h3>Top Labels</h3> -->
<div id="limetop_T" class="section-result"></div>
</div>
<div class="section" id="User_top_T_plot_base64">
<!-- <h3>Top Predicted Labels Plot</h3> -->
<div id="top_T_plot_base64"></div>
</div>
<div class="section" id="Dev_segment_overlay_base64">
<!-- <h3>LIME Segmentation</h3> -->
<div id="segment_overlay_base64"></div>
</div>
<div class="section" id="Dev_bar_plot_base64">
<!-- <h3>LIME Super Pixel Plot</h3> -->
<div id="bar_plot_base64"></div>
</div>
<div class="section" id="User_shapImageResult">
<!-- <h3>SHAP Image Result</h3> -->
<div id="shapImageResult"></div>
</div>
<div class="section" id="Dev_shap_S_plot_base64">
<!-- <h3>SHAP Summary Plot</h3> -->
<div id="shap_S_plot_base64"></div>
</div>
<div class="section" id="User_occlusionImageResult">
<!-- <h3>Occlusion Heatmap</h3> -->
<div id="occlusionImageResult"></div>
</div>
</form>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
// Occlusion Sensitivity Explanation
const occlusionForm = document.getElementById('occlusionForm');
const LoadingExplanations = document.getElementById('LoadingExplanations');
const occlusionImageFileInput = document.getElementById('occlusionImageFile');
const occlusionClassLabel = document.getElementById('occlusionClassLabel');
const occlusionExplanation = document.getElementById('occlusionExplanation');
const occlusionImageResult = document.getElementById('occlusionImageResult');
// SHAP Explanation
const shapImageFileInput = document.getElementById('shapImageFile');
const shapExplanation = document.getElementById('shapExplanation');
const shapImageResult = document.getElementById('shapImageResult');
const shap_S_plot_base64 = document.getElementById('shap_S_plot_base64');
const shappredictionResult = document.getElementById('shappredictionResult');
// LIME Explanation
const limeImageFileInput = document.getElementById('limeImageFile');
const limeExplanation = document.getElementById('limeExplanation');
const limetop_T = document.getElementById('limetop_T');
const top_T_plot_base64 = document.getElementById('top_T_plot_base64');
const limesegments = document.getElementById('limesegments');
const limeImageResult = document.getElementById('limeImageResult');
const bar_plot_base64 = document.getElementById('bar_plot_base64');
const segment_overlay_base64 = document.getElementById('segment_overlay_base64');
occlusionForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData();
formData.append('file', occlusionImageFileInput.files[0]);
const selectedLabel = occlusionClassLabel.value;
const queryParams = new URLSearchParams();
queryParams.append('imagetype', selectedLabel);
const queryString = queryParams.toString();
// Display the loading spinner
LoadingExplanations.innerHTML = '<div class="loader"></div>';
const response = await fetch(`/explain_all/image?${queryString}`, {
method: 'POST',
body: formData
});
const result = await response.json();
LoadingExplanations.innerHTML = '';
// Occlusion Sensitivity Explanation
// occlusionExplanation.innerHTML = `<b> Explanation :</b> ${result.Occexplanation}`
const Occ_dataURL = result.Occlimage_base64;
// Create an <img> element for the image
const image = document.createElement('img');
image.src = `data:image/jpeg;base64,${Occ_dataURL}`;
occlusionImageResult.innerHTML = '';
occlusionImageResult.appendChild(image);
// SHAP Explanation
shappredictionResult.innerHTML = '<b> Prediction : </b>' + result.prediction[0] + ',<b> Probability : </b>' + result.prediction[1];
// shapExplanation.innerHTML = `<b> Explanation :</b> ${result.Shapexplanation}`
const shap_dataURL = result.shap_V_plot_base64;
const shap_S__base64 = result.shap_S_plot_base64;
console.log("shap_S__base64");
console.log(shap_S__base64);
// Create an <img> element for the shap_V image
const image2 = document.createElement('img');
image2.src = `data:image/jpeg;base64,${shap_dataURL}`;
shapImageResult.innerHTML = '';
shapImageResult.appendChild(image2);
// Create an <img> element for the shap_S image
const image3 = document.createElement('img');
image3.src = `data:image/jpeg;base64,${shap_S__base64}`;
shap_S_plot_base64.innerHTML = '';
shap_S_plot_base64.appendChild(image3);
// LIME Explanation
// const lime_explanation = result.lime_explanation;
const top_T = result.top_T;
const top_T_plot = result.top_T_plot_base64;
// const segments = result.segments;
const Lime_dataURL = result.Lime_image_base64;
const bar_plot = result.bar_plot_base64;
const segment_overlay = result.segment_overlay_base64;
// Display explanations
// limeExplanation.innerHTML = `<b> Explanation :</b> ${lime_explanation}`;
// Display segments
// limesegments.innerHTML = `<b>Segments :</b> ${segments}`;
// Display top_T
limetop_T.innerHTML = `<b>Top Lables :</b> ${top_T}`;
// Create an <img> element for the image
const image4 = document.createElement('img');
image4.src = `data:image/jpeg;base64,${Lime_dataURL}`;
limeImageResult.innerHTML = '';
limeImageResult.appendChild(image4);
// Create an <img> element for the segment_overlay_base64
const image5 = document.createElement('img');
image5.src = `data:image/png;base64,${segment_overlay}`;
segment_overlay_base64.innerHTML = '';
segment_overlay_base64.appendChild(image5);
// // Create an <img> element for the bar_plot_base64
const image6 = document.createElement('img');
image6.src = `data:image/png;base64,${bar_plot}`;
bar_plot_base64.innerHTML = '';
bar_plot_base64.appendChild(image6);
// Create an <img> element for the top_T_plot_base64
const image7 = document.createElement('img');
image7.src = `data:image/png;base64,${top_T_plot}`;
top_T_plot_base64.innerHTML = '';
top_T_plot_base64.appendChild(image7);
});
function toggleSection(sectionId) {
const section = document.getElementById(sectionId);
const arrow = section.previousElementSibling.firstChild;
if (section.classList.contains('hidden')) {
section.classList.remove('hidden');
arrow.innerHTML = '▼';
} else {
section.classList.add('hidden');
arrow.innerHTML = '▶';
}
}
// Set the userRole in the UI
const userRoleElement = document.getElementById('userRole');
const userRole = 'business'; // Replace with the user's role
userRoleElement.textContent = userRole;
// Define the allowed roles for each section
const allowedRoles = {
User_shappredictionResult: ['user', 'developer', 'auditor', 'business'], // Prediction & Probability
User_limeImageResult: ['user', 'developer', 'auditor'], // Lime Image
User_limetop_T: ['user', 'developer', 'auditor', 'business'], // Top Lables array
User_top_T_plot_base64: ['user', 'developer', 'auditor', 'business'], // Top Predicted Labels plot
Dev_segment_overlay_base64: ['developer', 'auditor'], // Lime Segmentation of image
Dev_bar_plot_base64: ['developer', 'auditor'], // Lime Segmentation super pixel plot
User_shapImageResult: ['user', 'developer', 'auditor', 'business'], // Shap Image
Dev_shap_S_plot_base64: ['developer', 'auditor'], // **Need to add Shap Summary Image** //
User_occlusionImageResult: ['user', 'developer', 'auditor', 'business'] // Occlusion heat image
};
// Function to check if a role is allowed for a section
function isRoleAllowed(sectionId, role) {
const allowed = allowedRoles[sectionId];
return allowed && allowed.includes(role);
}
// Function to hide sections based on user role
function hideSectionsBasedOnRole(role) {
const sections = document.getElementsByClassName('section');
for (let i = 0; i < sections.length; i++) {
const section = sections[i];
const sectionId = section.getAttribute('id');
if (!isRoleAllowed(sectionId, role)) {
section.classList.add('hidden');
}
}
}
// Hide sections based on user role
hideSectionsBasedOnRole(userRole);
</script>
</body>
</html>