Hanan-Alnakhal commited on
Commit
1a9762b
·
verified ·
1 Parent(s): cad89d4

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +17 -4
static/script.js CHANGED
@@ -150,17 +150,24 @@ async function uploadFile(file) {
150
  }
151
 
152
  async function generateExplanations() {
153
- showLoading('Generating AI explanations... This may take 30-60 seconds.');
154
 
155
  try {
 
 
 
 
156
  const response = await fetch('/api/explain', {
157
  method: 'POST',
158
  headers: {
159
  'Content-Type': 'application/json'
160
  },
161
- body: JSON.stringify({ session_id: sessionId })
 
162
  });
163
 
 
 
164
  const data = await response.json();
165
 
166
  if (!response.ok) {
@@ -168,10 +175,16 @@ async function generateExplanations() {
168
  }
169
 
170
  explanations = data.explanations;
171
- console.log('Explanations:', explanations);
172
 
173
  } catch (error) {
174
- showToast('Error generating explanations: ' + error.message, 'error');
 
 
 
 
 
 
175
  // Continue anyway to show results
176
  } finally {
177
  hideLoading();
 
150
  }
151
 
152
  async function generateExplanations() {
153
+ showLoading('Generating AI explanations... (10-20 seconds)');
154
 
155
  try {
156
+ // Add timeout to prevent hanging
157
+ const controller = new AbortController();
158
+ const timeoutId = setTimeout(() => controller.abort(), 60000); // 60 second timeout
159
+
160
  const response = await fetch('/api/explain', {
161
  method: 'POST',
162
  headers: {
163
  'Content-Type': 'application/json'
164
  },
165
+ body: JSON.stringify({ session_id: sessionId }),
166
+ signal: controller.signal
167
  });
168
 
169
+ clearTimeout(timeoutId);
170
+
171
  const data = await response.json();
172
 
173
  if (!response.ok) {
 
175
  }
176
 
177
  explanations = data.explanations;
178
+ console.log('Explanations generated:', Object.keys(explanations).length);
179
 
180
  } catch (error) {
181
+ if (error.name === 'AbortError') {
182
+ console.log('Explanation generation timed out - showing basic results');
183
+ showToast('Loading took longer than expected. Showing basic results.', 'info');
184
+ } else {
185
+ console.error('Error generating explanations:', error);
186
+ showToast('Some explanations may be unavailable', 'info');
187
+ }
188
  // Continue anyway to show results
189
  } finally {
190
  hideLoading();