lsmpp commited on
Commit
86762b4
·
verified ·
1 Parent(s): df87cf3

Recover completed results when an SSE stream closes

Browse files
Files changed (1) hide show
  1. static/app.js +9 -1
static/app.js CHANGED
@@ -184,7 +184,15 @@ async function submitGradio(sid, body) {
184
  if(update?.progress!=null)$('progressFill').style.width=`${Math.round(update.progress*100)}%`;
185
  }
186
  }
187
- if(!result)throw new Error('No result was returned. Please retry.');
 
 
 
 
 
 
 
 
188
  return result;
189
  }
190
 
 
184
  if(update?.progress!=null)$('progressFill').style.width=`${Math.round(update.progress*100)}%`;
185
  }
186
  }
187
+ if(!result){
188
+ let latest=await api(`/api/sessions/${sid}/job`);
189
+ for(let attempt=0;attempt<150&&['queued','running'].includes(latest.status);attempt++){
190
+ await new Promise(resolve=>setTimeout(resolve,1000));
191
+ latest=await api(`/api/sessions/${sid}/jobs/${latest.id}`);
192
+ }
193
+ if(latest.status==='done')result={job_id:latest.id,result:latest.result};
194
+ else throw new Error(latest.message||'The request could not finish. Please retry.');
195
+ }
196
  return result;
197
  }
198