@@ -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
@@ -527,20 +534,24 @@ def list_recordings(save_recording_path):
527
534
lambda provider , api_key , base_url : update_model_dropdown (provider , api_key , base_url ),
528
535
inputs = [llm_provider , llm_api_key , llm_base_url ],
529
536
outputs = llm_model_name
530
- )
531
-
537
+ )
538
+
532
539
# Add this after defining the components
533
540
enable_recording .change (
534
541
lambda enabled : gr .update (interactive = enabled ),
535
542
inputs = enable_recording ,
536
543
outputs = save_recording_path
537
544
)
538
-
545
+
539
546
# Run button click handler
540
547
run_button .click (
541
548
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 ],
544
555
)
545
556
546
557
return demo
0 commit comments