@@ -49,21 +49,29 @@ async def run_browser_agent(
49
49
window_w ,
50
50
window_h ,
51
51
save_recording_path ,
52
+ enable_recording ,
52
53
task ,
53
54
add_infos ,
54
55
max_steps ,
55
56
use_vision ,
56
57
max_actions_per_step ,
57
58
tool_call_in_content
58
59
):
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 )
61
67
62
68
# 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
+ )
67
75
68
76
# Run the agent
69
77
llm = utils .get_llm_model (
@@ -106,16 +114,15 @@ async def run_browser_agent(
106
114
else :
107
115
raise ValueError (f"Invalid agent type: { agent_type } " )
108
116
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)
116
118
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
119
126
120
127
return final_result , errors , model_actions , model_thoughts , latest_video
121
128
@@ -419,6 +426,11 @@ def create_ui(theme_name="Ocean"):
419
426
value = True ,
420
427
info = "Disable browser security features" ,
421
428
)
429
+ enable_recording = gr .Checkbox (
430
+ label = "Enable Recording" ,
431
+ value = True ,
432
+ info = "Enable saving browser recordings" ,
433
+ )
422
434
423
435
with gr .Row ():
424
436
window_w = gr .Number (
@@ -437,6 +449,7 @@ def create_ui(theme_name="Ocean"):
437
449
placeholder = "e.g. ./tmp/record_videos" ,
438
450
value = "./tmp/record_videos" ,
439
451
info = "Path to save browser recordings" ,
452
+ interactive = True , # Allow editing only if recording is enabled
440
453
)
441
454
442
455
with gr .TabItem ("🤖 Run Agent" , id = 4 ):
@@ -523,11 +536,22 @@ def list_recordings(save_recording_path):
523
536
outputs = llm_model_name
524
537
)
525
538
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
+
526
546
# Run button click handler
527
547
run_button .click (
528
548
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 ],
531
555
)
532
556
533
557
return demo
0 commit comments