@@ -148,9 +148,9 @@ async def run_org_agent(
148
148
):
149
149
browser = Browser (
150
150
config = BrowserConfig (
151
- headless = headless , # Force non-headless for streaming
151
+ headless = headless ,
152
152
disable_security = disable_security ,
153
- extra_chromium_args = [f' --window-size={ window_w } ,{ window_h } ' ],
153
+ extra_chromium_args = [f" --window-size={ window_w } ,{ window_h } " ],
154
154
)
155
155
)
156
156
async with await browser .new_context (
@@ -181,8 +181,8 @@ async def run_org_agent(
181
181
recorded_files = get_latest_files (save_recording_path )
182
182
trace_file = get_latest_files (save_trace_path )
183
183
184
- await browser .close ()
185
- return final_result , errors , model_actions , model_thoughts , recorded_files .get ('.webm' ), trace_file .get ('.zip' )
184
+ await browser .close ()
185
+ return final_result , errors , model_actions , model_thoughts , recorded_files .get ('.webm' ), trace_file .get ('.zip' )
186
186
187
187
async def run_custom_agent (
188
188
llm ,
@@ -438,30 +438,6 @@ async def run_with_stream(
438
438
None ,
439
439
]
440
440
441
- # Update the main function to handle cleanup
442
- def main ():
443
- async def cleanup ():
444
- global _global_browser , _global_browser_context
445
- if _global_browser_context :
446
- await _global_browser_context .close ()
447
- if _global_browser :
448
- await _global_browser .close ()
449
- _global_browser = None
450
- _global_browser_context = None
451
-
452
- parser = argparse .ArgumentParser (description = "Gradio UI for Browser Agent" )
453
- parser .add_argument ("--ip" , type = str , default = "127.0.0.1" , help = "IP address to bind to" )
454
- parser .add_argument ("--port" , type = int , default = 7788 , help = "Port to listen on" )
455
- parser .add_argument ("--theme" , type = str , default = "Ocean" , choices = theme_map .keys (), help = "Theme to use for the UI" )
456
- parser .add_argument ("--dark-mode" , action = "store_true" , help = "Enable dark mode" )
457
- args = parser .parse_args ()
458
-
459
- try :
460
- demo = create_ui (theme_name = args .theme )
461
- demo .launch (server_name = args .ip , server_port = args .port )
462
- finally :
463
- asyncio .get_event_loop ().run_until_complete (cleanup ())
464
-
465
441
# Define the theme map globally
466
442
theme_map = {
467
443
"Default" : Default (),
@@ -751,5 +727,18 @@ def list_recordings(save_recording_path):
751
727
752
728
return demo
753
729
730
+
731
+ # Update the main function to handle cleanup
732
+ def main ():
733
+ parser = argparse .ArgumentParser (description = "Gradio UI for Browser Agent" )
734
+ parser .add_argument ("--ip" , type = str , default = "127.0.0.1" , help = "IP address to bind to" )
735
+ parser .add_argument ("--port" , type = int , default = 7788 , help = "Port to listen on" )
736
+ parser .add_argument ("--theme" , type = str , default = "Ocean" , choices = theme_map .keys (), help = "Theme to use for the UI" )
737
+ parser .add_argument ("--dark-mode" , action = "store_true" , help = "Enable dark mode" )
738
+ args = parser .parse_args ()
739
+
740
+ demo = create_ui (theme_name = args .theme )
741
+ demo .launch (server_name = args .ip , server_port = args .port )
742
+
754
743
if __name__ == '__main__' :
755
744
main ()
0 commit comments