Skip to content

Commit 786d0ae

Browse files
authored
Merge pull request #55 from richard-devbot/main
Enable/Disable Recordings
2 parents 70d014e + 76deffa commit 786d0ae

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

webui.py

Lines changed: 41 additions & 17 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

@@ -419,6 +426,11 @@ def create_ui(theme_name="Ocean"):
419426
value=True,
420427
info="Disable browser security features",
421428
)
429+
enable_recording = gr.Checkbox(
430+
label="Enable Recording",
431+
value=True,
432+
info="Enable saving browser recordings",
433+
)
422434

423435
with gr.Row():
424436
window_w = gr.Number(
@@ -437,6 +449,7 @@ def create_ui(theme_name="Ocean"):
437449
placeholder="e.g. ./tmp/record_videos",
438450
value="./tmp/record_videos",
439451
info="Path to save browser recordings",
452+
interactive=True, # Allow editing only if recording is enabled
440453
)
441454

442455
with gr.TabItem("🤖 Run Agent", id=4):
@@ -523,11 +536,22 @@ def list_recordings(save_recording_path):
523536
outputs=llm_model_name
524537
)
525538

539+
# Add this after defining the components
540+
enable_recording.change(
541+
lambda enabled: gr.update(interactive=enabled),
542+
inputs=enable_recording,
543+
outputs=save_recording_path
544+
)
545+
526546
# Run button click handler
527547
run_button.click(
528548
fn=run_browser_agent,
529-
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],
530-
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],
531555
)
532556

533557
return demo

0 commit comments

Comments
 (0)