Skip to content

Commit 76deffa

Browse files
Update webui.py
added enable/disable for recordings
1 parent a91376c commit 76deffa

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

webui.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ async def run_browser_agent(
4949
window_w,
5050
window_h,
5151
save_recording_path,
52+
enable_recording,
5253
task,
5354
add_infos,
5455
max_steps,
5556
use_vision,
5657
max_actions_per_step,
5758
tool_call_in_content
5859
):
59-
# Ensure the recording directory exists
60-
os.makedirs(save_recording_path, exist_ok=True)
60+
# Disable recording if the checkbox is unchecked
61+
if not enable_recording:
62+
save_recording_path = None
63+
64+
# Ensure the recording directory exists if recording is enabled
65+
if save_recording_path:
66+
os.makedirs(save_recording_path, exist_ok=True)
6167

6268
# Get the list of existing videos before the agent runs
63-
existing_videos = set(
64-
glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4"))
65-
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
66-
)
69+
existing_videos = set()
70+
if save_recording_path:
71+
existing_videos = set(
72+
glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4"))
73+
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
74+
)
6775

6876
# Run the agent
6977
llm = utils.get_llm_model(
@@ -106,16 +114,15 @@ async def run_browser_agent(
106114
else:
107115
raise ValueError(f"Invalid agent type: {agent_type}")
108116

109-
# Get the list of videos after the agent runs
110-
new_videos = set(
111-
glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4"))
112-
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
113-
)
114-
115-
# Find the newly created video
117+
# Get the list of videos after the agent runs (if recording is enabled)
116118
latest_video = None
117-
if new_videos - existing_videos:
118-
latest_video = list(new_videos - existing_videos)[0] # Get the first new video
119+
if save_recording_path:
120+
new_videos = set(
121+
glob.glob(os.path.join(save_recording_path, "*.[mM][pP]4"))
122+
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
123+
)
124+
if new_videos - existing_videos:
125+
latest_video = list(new_videos - existing_videos)[0] # Get the first new video
119126

120127
return final_result, errors, model_actions, model_thoughts, latest_video
121128

@@ -527,20 +534,24 @@ def list_recordings(save_recording_path):
527534
lambda provider, api_key, base_url: update_model_dropdown(provider, api_key, base_url),
528535
inputs=[llm_provider, llm_api_key, llm_base_url],
529536
outputs=llm_model_name
530-
)
531-
537+
)
538+
532539
# Add this after defining the components
533540
enable_recording.change(
534541
lambda enabled: gr.update(interactive=enabled),
535542
inputs=enable_recording,
536543
outputs=save_recording_path
537544
)
538-
545+
539546
# Run button click handler
540547
run_button.click(
541548
fn=run_browser_agent,
542-
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],
543-
outputs=[final_result_output, errors_output, model_actions_output, model_thoughts_output, recording_display,],
549+
inputs=[
550+
agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
551+
use_own_browser, headless, disable_security, window_w, window_h, save_recording_path,
552+
enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_call_in_content
553+
],
554+
outputs=[final_result_output, errors_output, model_actions_output, model_thoughts_output, recording_display],
544555
)
545556

546557
return demo

0 commit comments

Comments
 (0)