Miquel Farré
commited on
Commit
·
701026e
1
Parent(s):
28d5a31
changing behavior after failure
Browse files
app.py
CHANGED
|
@@ -219,27 +219,11 @@ function() {
|
|
| 219 |
console.log("Error detected!");
|
| 220 |
showBSOD('Error');
|
| 221 |
clearInterval(resultsInterval);
|
| 222 |
-
window.agentFailed = true;
|
| 223 |
break;
|
| 224 |
}
|
| 225 |
}
|
| 226 |
}, 1000);
|
| 227 |
};
|
| 228 |
-
|
| 229 |
-
// Add a new function to conditionally go to interactive mode
|
| 230 |
-
window.shouldSwitchToInteractive = function() {
|
| 231 |
-
const resultsElements = document.querySelectorAll('textarea, .output-text');
|
| 232 |
-
for (let elem of resultsElements) {
|
| 233 |
-
const content = elem.value || elem.innerText || '';
|
| 234 |
-
// If we see an error message or our flag is set, don't switch to interactive
|
| 235 |
-
if (content.includes('Error running agent') || window.agentFailed === true) {
|
| 236 |
-
console.log("Error detected, not switching to interactive mode");
|
| 237 |
-
return false;
|
| 238 |
-
}
|
| 239 |
-
}
|
| 240 |
-
console.log("No errors detected, switching to interactive mode");
|
| 241 |
-
return true;
|
| 242 |
-
};
|
| 243 |
|
| 244 |
|
| 245 |
// Start monitoring for timeouts immediately
|
|
@@ -253,7 +237,6 @@ function() {
|
|
| 253 |
if (e.target.tagName === 'BUTTON') {
|
| 254 |
if (e.target.innerText === "Let's go!") {
|
| 255 |
resetBSOD();
|
| 256 |
-
window.agentFailed = false;
|
| 257 |
}
|
| 258 |
setTimeout(monitorForErrors, 3000);
|
| 259 |
}
|
|
@@ -487,6 +470,17 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 487 |
def set_interactive_mode(request: gr.Request):
|
| 488 |
return update_html(True, request)
|
| 489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
# Chain the events
|
| 491 |
# 1. Set view-only mode when button is clicked
|
| 492 |
view_only_event = update_btn.click(
|
|
@@ -494,21 +488,19 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
| 494 |
inputs=[task_input],
|
| 495 |
outputs=html_output
|
| 496 |
)
|
| 497 |
-
|
| 498 |
# 2. Then run the agent task
|
| 499 |
task_result = view_only_event.then(
|
| 500 |
fn=run_agent_task,
|
| 501 |
inputs=[task_input],
|
| 502 |
outputs=results_output
|
| 503 |
)
|
| 504 |
-
|
| 505 |
-
#
|
| 506 |
task_result.then(
|
| 507 |
-
fn=
|
| 508 |
-
inputs=
|
| 509 |
-
outputs=html_output
|
| 510 |
-
_js="() => window.shouldSwitchToInteractive() ? [] : null"
|
| 511 |
-
|
| 512 |
)
|
| 513 |
|
| 514 |
# Load the sandbox on app start with initial HTML
|
|
|
|
| 219 |
console.log("Error detected!");
|
| 220 |
showBSOD('Error');
|
| 221 |
clearInterval(resultsInterval);
|
|
|
|
| 222 |
break;
|
| 223 |
}
|
| 224 |
}
|
| 225 |
}, 1000);
|
| 226 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
|
| 229 |
// Start monitoring for timeouts immediately
|
|
|
|
| 237 |
if (e.target.tagName === 'BUTTON') {
|
| 238 |
if (e.target.innerText === "Let's go!") {
|
| 239 |
resetBSOD();
|
|
|
|
| 240 |
}
|
| 241 |
setTimeout(monitorForErrors, 3000);
|
| 242 |
}
|
|
|
|
| 470 |
def set_interactive_mode(request: gr.Request):
|
| 471 |
return update_html(True, request)
|
| 472 |
|
| 473 |
+
|
| 474 |
+
# Function to check result and conditionally set interactive mode
|
| 475 |
+
def check_and_set_interactive(result, request: gr.Request):
|
| 476 |
+
if result and not result.startswith("Error running agent"):
|
| 477 |
+
# Only set interactive mode if no error
|
| 478 |
+
return update_html(True, request)
|
| 479 |
+
else:
|
| 480 |
+
# Return the current HTML to avoid changing the display
|
| 481 |
+
# This will keep the BSOD visible
|
| 482 |
+
return gr.update()
|
| 483 |
+
|
| 484 |
# Chain the events
|
| 485 |
# 1. Set view-only mode when button is clicked
|
| 486 |
view_only_event = update_btn.click(
|
|
|
|
| 488 |
inputs=[task_input],
|
| 489 |
outputs=html_output
|
| 490 |
)
|
| 491 |
+
|
| 492 |
# 2. Then run the agent task
|
| 493 |
task_result = view_only_event.then(
|
| 494 |
fn=run_agent_task,
|
| 495 |
inputs=[task_input],
|
| 496 |
outputs=results_output
|
| 497 |
)
|
| 498 |
+
|
| 499 |
+
# 3. Then check the result and conditionally set to interactive mode
|
| 500 |
task_result.then(
|
| 501 |
+
fn=check_and_set_interactive,
|
| 502 |
+
inputs=[results_output], # Pass the result text to check
|
| 503 |
+
outputs=html_output
|
|
|
|
|
|
|
| 504 |
)
|
| 505 |
|
| 506 |
# Load the sandbox on app start with initial HTML
|