From a91376c12b1f3713b891dc5732b596da8c6eb8d2 Mon Sep 17 00:00:00 2001 From: Richardson Gunde <152559661+richard-devbot@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:48:02 +0530 Subject: [PATCH 1/2] Update webui.py --- webui.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 85a5299..196ed8c 100644 --- a/webui.py +++ b/webui.py @@ -419,6 +419,11 @@ def create_ui(theme_name="Ocean"): value=True, info="Disable browser security features", ) + enable_recording = gr.Checkbox( + label="Enable Recording", + value=True, + info="Enable saving browser recordings", + ) with gr.Row(): window_w = gr.Number( @@ -437,6 +442,7 @@ def create_ui(theme_name="Ocean"): placeholder="e.g. ./tmp/record_videos", value="./tmp/record_videos", info="Path to save browser recordings", + interactive=True, # Allow editing only if recording is enabled ) with gr.TabItem("🤖 Run Agent", id=4): @@ -521,7 +527,14 @@ def create_ui(theme_name="Ocean"): lambda provider, api_key, base_url: update_model_dropdown(provider, api_key, base_url), inputs=[llm_provider, llm_api_key, llm_base_url], outputs=llm_model_name - ) + ) + + # Add this after defining the components + enable_recording.change( + lambda enabled: gr.update(interactive=enabled), + inputs=enable_recording, + outputs=save_recording_path + ) # Run button click handler run_button.click( From 76deffa15ddeadbb8086079da4969d6f6e6ffe9c Mon Sep 17 00:00:00 2001 From: Richardson Gunde <152559661+richard-devbot@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:51:17 +0530 Subject: [PATCH 2/2] Update webui.py added enable/disable for recordings --- webui.py | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/webui.py b/webui.py index 196ed8c..9f8fcb5 100644 --- a/webui.py +++ b/webui.py @@ -49,6 +49,7 @@ async def run_browser_agent( window_w, window_h, save_recording_path, + enable_recording, task, add_infos, max_steps, @@ -56,14 +57,21 @@ async def run_browser_agent( max_actions_per_step, tool_call_in_content ): - # Ensure the recording directory exists - os.makedirs(save_recording_path, exist_ok=True) + # Disable recording if the checkbox is unchecked + if not enable_recording: + save_recording_path = None + + # Ensure the recording directory exists if recording is enabled + if save_recording_path: + os.makedirs(save_recording_path, exist_ok=True) # Get the list of existing videos before the agent runs - existing_videos = set( - glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4")) - + glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]")) - ) + existing_videos = set() + if save_recording_path: + existing_videos = set( + glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4")) + + glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]")) + ) # Run the agent llm = utils.get_llm_model( @@ -106,16 +114,15 @@ async def run_browser_agent( else: raise ValueError(f"Invalid agent type: {agent_type}") - # Get the list of videos after the agent runs - new_videos = set( - glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4")) - + glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]")) - ) - - # Find the newly created video + # Get the list of videos after the agent runs (if recording is enabled) latest_video = None - if new_videos - existing_videos: - latest_video = list(new_videos - existing_videos)[0] # Get the first new video + if save_recording_path: + new_videos = set( + glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4")) + + glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]")) + ) + if new_videos - existing_videos: + latest_video = list(new_videos - existing_videos)[0] # Get the first new video return final_result, errors, model_actions, model_thoughts, latest_video @@ -527,20 +534,24 @@ def create_ui(theme_name="Ocean"): lambda provider, api_key, base_url: update_model_dropdown(provider, api_key, base_url), inputs=[llm_provider, llm_api_key, llm_base_url], outputs=llm_model_name - ) - + ) + # Add this after defining the components enable_recording.change( lambda enabled: gr.update(interactive=enabled), inputs=enable_recording, outputs=save_recording_path ) - + # Run button click handler run_button.click( fn=run_browser_agent, - inputs=[agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, use_own_browser, headless, disable_security, window_w, window_h, save_recording_path, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_call_in_content], - outputs=[final_result_output, errors_output, model_actions_output, model_thoughts_output, recording_display,], + inputs=[ + agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, + use_own_browser, headless, disable_security, window_w, window_h, save_recording_path, + enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_call_in_content + ], + outputs=[final_result_output, errors_output, model_actions_output, model_thoughts_output, recording_display], ) return demo