userisuser commited on
Commit
a2b6a97
Β·
1 Parent(s): 8757ce8

Handle Gradio completion status

Browse files
Files changed (1) hide show
  1. index.html +8 -1
index.html CHANGED
@@ -590,7 +590,7 @@
590
 
591
  async function init() {
592
  try {
593
- client = await Client.connect(window.location.origin);
594
  } catch (err) { console.error("Gradio Connection Error", err); }
595
  }
596
  init();
@@ -823,6 +823,13 @@
823
  if (msg.type === "data" && msg.data) {
824
  const chunk = msg.data[0];
825
  finalAnswer = updateBotMessage(botDiv, chunk);
 
 
 
 
 
 
 
826
  }
827
  }
828
 
 
590
 
591
  async function init() {
592
  try {
593
+ client = await Client.connect(window.location.origin, { events: ["data", "status"] });
594
  } catch (err) { console.error("Gradio Connection Error", err); }
595
  }
596
  init();
 
823
  if (msg.type === "data" && msg.data) {
824
  const chunk = msg.data[0];
825
  finalAnswer = updateBotMessage(botDiv, chunk);
826
+ } else if (msg.type === "status") {
827
+ if (msg.stage === "complete") {
828
+ break;
829
+ }
830
+ if (msg.stage === "error") {
831
+ throw new Error(msg.message || "Generation failed");
832
+ }
833
  }
834
  }
835