diff --git a/requirements.txt b/requirements.txt index e0ddf89..619ee66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -browser-use==0.1.18 +browser-use==0.1.19 langchain-google-genai==2.0.8 pyperclip==1.9.0 gradio==5.9.1 diff --git a/webui.py b/webui.py index bc73c40..b7acffe 100644 --- a/webui.py +++ b/webui.py @@ -189,7 +189,7 @@ async def run_browser_agent( trace_file, history_file, gr.update(value="Stop", interactive=True), # Re-enable stop button - gr.update(value="Run", interactive=True) # Re-enable run button + gr.update(interactive=True) # Re-enable run button ) except Exception as e: @@ -205,7 +205,7 @@ async def run_browser_agent( None, # history_file None, # trace_file gr.update(value="Stop", interactive=True), # Re-enable stop button - gr.update(value="Run", interactive=True) # Re-enable run button + gr.update(interactive=True) # Re-enable run button ) @@ -422,6 +422,7 @@ async def run_with_stream( max_actions_per_step, tool_call_in_content ): + global _global_agent_state stream_vw = 80 stream_vh = int(80 * window_h // window_w) if not headless: @@ -454,6 +455,7 @@ async def run_with_stream( yield [html_content] + list(result) else: try: + _global_agent_state.clear_stop() # Run the browser agent in the background agent_task = asyncio.create_task( run_browser_agent( @@ -485,7 +487,7 @@ async def run_with_stream( # Initialize values for streaming html_content = f"

Using browser...

" final_result = errors = model_actions = model_thoughts = "" - latest_videos = trace = None + latest_videos = trace = history_file = None # Periodically update the stream while the agent task is running @@ -498,27 +500,40 @@ async def run_with_stream( html_content = f"

Waiting for browser session...

" except Exception as e: html_content = f"

Waiting for browser session...

" - - yield [ - html_content, - final_result, - errors, - model_actions, - model_thoughts, - latest_videos, - trace, - gr.update(value="Stop", interactive=True), # Re-enable stop button - gr.update(value="Run", interactive=True) # Re-enable run button - ] + + if _global_agent_state and _global_agent_state.is_stop_requested(): + yield [ + html_content, + final_result, + errors, + model_actions, + model_thoughts, + latest_videos, + trace, + history_file, + gr.update(value="Stopping...", interactive=False), # stop_button + gr.update(interactive=False), # run_button + ] + break + else: + yield [ + html_content, + final_result, + errors, + model_actions, + model_thoughts, + latest_videos, + trace, + history_file, + gr.update(value="Stop", interactive=True), # Re-enable stop button + gr.update(interactive=True) # Re-enable run button + ] await asyncio.sleep(0.05) # Once the agent task completes, get the results try: result = await agent_task - if isinstance(result, tuple) and len(result) == 8: - final_result, errors, model_actions, model_thoughts, latest_videos, trace, stop_button, run_button = result - else: - errors = "Unexpected result format from agent" + final_result, errors, model_actions, model_thoughts, latest_videos, trace, history_file, stop_button, run_button = result except Exception as e: errors = f"Agent error: {str(e)}" @@ -530,6 +545,7 @@ async def run_with_stream( model_thoughts, latest_videos, trace, + history_file, stop_button, run_button ] @@ -544,8 +560,9 @@ async def run_with_stream( "", None, None, + None, gr.update(value="Stop", interactive=True), # Re-enable stop button - gr.update(value="Run", interactive=True) # Re-enable run button + gr.update(interactive=True) # Re-enable run button ] # Define the theme map globally