Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Miquel Farré
commited on
Commit
·
28d5a31
1
Parent(s):
0185d4a
changing behavior after failure
Browse files
app.py
CHANGED
@@ -219,11 +219,28 @@ function() {
|
|
219 |
console.log("Error detected!");
|
220 |
showBSOD('Error');
|
221 |
clearInterval(resultsInterval);
|
|
|
222 |
break;
|
223 |
}
|
224 |
}
|
225 |
}, 1000);
|
226 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
// Start monitoring for timeouts immediately
|
229 |
checkSandboxTimeout();
|
@@ -236,6 +253,7 @@ function() {
|
|
236 |
if (e.target.tagName === 'BUTTON') {
|
237 |
if (e.target.innerText === "Let's go!") {
|
238 |
resetBSOD();
|
|
|
239 |
}
|
240 |
setTimeout(monitorForErrors, 3000);
|
241 |
}
|
@@ -485,26 +503,12 @@ with gr.Blocks(css=custom_css, js=custom_js) as demo:
|
|
485 |
)
|
486 |
|
487 |
# # 3. Then set back to interactive mode
|
488 |
-
# task_result.then(
|
489 |
-
# fn=set_interactive_mode,
|
490 |
-
# inputs=None, # No inputs needed here
|
491 |
-
# outputs=html_output
|
492 |
-
# )
|
493 |
-
|
494 |
-
# 3. Define a function to check the result and only return to interactive mode if successful
|
495 |
-
def check_result_and_set_mode(result, request: gr.Request):
|
496 |
-
# Only switch back to interactive mode if the agent completed successfully
|
497 |
-
if result.startswith("Task completed:"):
|
498 |
-
return update_html(True, request)
|
499 |
-
else:
|
500 |
-
# Keep the view-only mode (with BSOD displayed by JS)
|
501 |
-
return None
|
502 |
-
|
503 |
-
# 3. Then conditionally set back to interactive mode based on success
|
504 |
task_result.then(
|
505 |
-
fn=
|
506 |
-
inputs=
|
507 |
-
outputs=html_output
|
|
|
|
|
508 |
)
|
509 |
|
510 |
# Load the sandbox on app start with initial HTML
|
|
|
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
|
246 |
checkSandboxTimeout();
|
|
|
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 |
}
|
|
|
503 |
)
|
504 |
|
505 |
# # 3. Then set back to interactive mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
task_result.then(
|
507 |
+
fn=set_interactive_mode,
|
508 |
+
inputs=None, # No inputs needed here
|
509 |
+
outputs=html_output,
|
510 |
+
_js="() => window.shouldSwitchToInteractive() ? [] : null"
|
511 |
+
|
512 |
)
|
513 |
|
514 |
# Load the sandbox on app start with initial HTML
|