1212import numpy as np
1313import pandas as pd
1414from attr import dataclass
15- from browsergym .experiments .loop import ExpResult , StepInfo
1615from langchain .schema import BaseMessage , HumanMessage
1716from openai import OpenAI
1817from PIL import Image
1918
2019from agentlab .analyze import inspect_results
2120from agentlab .experiments .exp_utils import RESULTS_DIR
21+ from agentlab .experiments .loop import ExpResult , StepInfo
2222from agentlab .experiments .study import get_most_recent_study
2323from agentlab .llm .chat_api import make_system_message , make_user_message
2424from agentlab .llm .llm_utils import BaseMessage as AgentLabBaseMessage
@@ -201,7 +201,6 @@ def run_gradio(results_dir: Path):
201201"""
202202 )
203203 with gr .Row ():
204-
205204 exp_dir_choice = gr .Dropdown (
206205 choices = get_directory_contents (results_dir ),
207206 value = select_dir_instructions ,
@@ -297,7 +296,10 @@ def run_gradio(results_dir: Path):
297296 state_error = gr .Markdown (label = "Next Step Error" , elem_classes = "my-markdown" )
298297
299298 profiling_gr = gr .Image (
300- label = "Profiling" , show_label = False , interactive = False , show_download_button = False
299+ label = "Profiling" ,
300+ show_label = False ,
301+ interactive = False ,
302+ show_download_button = False ,
301303 )
302304
303305 gr .HTML (
@@ -418,7 +420,14 @@ def run_gradio(results_dir: Path):
418420 exp_dir_choice .change (
419421 fn = new_exp_dir ,
420422 inputs = exp_dir_choice ,
421- outputs = [agent_table , agent_id , constants , variables , global_stats , error_report ],
423+ outputs = [
424+ agent_table ,
425+ agent_id ,
426+ constants ,
427+ variables ,
428+ global_stats ,
429+ error_report ,
430+ ],
422431 )
423432
424433 agent_table .select (fn = on_select_agent , inputs = agent_table , outputs = [agent_id ])
@@ -454,7 +463,8 @@ def run_gradio(results_dir: Path):
454463 screenshot_gallery .select (fn = gallery_step_change , inputs = episode_id , outputs = step_id )
455464 step_id .change (fn = if_active ("DOM HTML" )(update_html ), outputs = html_code )
456465 step_id .change (
457- fn = if_active ("Pruned DOM HTML" )(update_pruned_html ), outputs = pruned_html_code
466+ fn = if_active ("Pruned DOM HTML" )(update_pruned_html ),
467+ outputs = pruned_html_code ,
458468 )
459469 step_id .change (fn = if_active ("AXTree" )(update_axtree ), outputs = axtree_code )
460470 step_id .change (fn = if_active ("Chat Messages" )(update_chat_messages ), outputs = chat_messages )
@@ -475,10 +485,14 @@ def run_gradio(results_dir: Path):
475485 # we need to update them individually when the tab is selected
476486 tab_screenshot .select (fn = update_screenshot , inputs = som_or_not , outputs = screenshot )
477487 tab_screenshot_pair .select (
478- fn = update_screenshot_pair , inputs = som_or_not , outputs = [screenshot1 , screenshot2 ]
488+ fn = update_screenshot_pair ,
489+ inputs = som_or_not ,
490+ outputs = [screenshot1 , screenshot2 ],
479491 )
480492 tab_screenshot_gallery .select (
481- fn = update_screenshot_gallery , inputs = som_or_not , outputs = [screenshot_gallery ]
493+ fn = update_screenshot_gallery ,
494+ inputs = som_or_not ,
495+ outputs = [screenshot_gallery ],
482496 )
483497 tab_html .select (fn = update_html , outputs = html_code )
484498 tab_pruned_html .select (fn = update_pruned_html , outputs = pruned_html_code )
@@ -617,7 +631,7 @@ def update_logs():
617631 try :
618632 return f"""{ info .exp_result .logs } """
619633 except FileNotFoundError :
620- return f """No Logs"""
634+ return """No Logs"""
621635
622636
623637def update_stats ():
@@ -757,11 +771,11 @@ def get_episode_info(info: Info):
757771
758772 info = f"""\
759773 ### { env_args .task_name } (seed: { env_args .task_seed } )
760- ### Step { info .step } / { len (steps_info )- 1 } (Reward: { cum_reward :.1f} )
774+ ### Step { info .step } / { len (steps_info ) - 1 } (Reward: { cum_reward :.1f} )
761775
762776**Goal:**
763777
764- { code (str (AgentLabBaseMessage ('' , goal )))}
778+ { code (str (AgentLabBaseMessage ("" , goal )))}
765779
766780**Task info:**
767781
@@ -770,7 +784,7 @@ def get_episode_info(info: Info):
770784**exp_dir:**
771785
772786<small style="line-height: 1; margin: 0; padding: 0;">{ code (exp_dir_str )} </small>"""
773- except Exception as e :
787+ except Exception :
774788 info = f"""\
775789 **Error while getting episode info**
776790{ code (traceback .format_exc ())} """
@@ -942,7 +956,6 @@ def update_error_report():
942956
943957
944958def new_exp_dir (exp_dir , progress = gr .Progress (), just_refresh = False ):
945-
946959 if exp_dir == select_dir_instructions :
947960 return None , None
948961
@@ -1075,7 +1088,6 @@ def add_patch(ax, start, stop, color, label, edge=False):
10751088
10761089
10771090def plot_profiling (ax , step_info_list : list [StepInfo ], summary_info : dict , progress_fn ):
1078-
10791091 if len (step_info_list ) == 0 :
10801092 warning ("No step info to plot" )
10811093 return None
@@ -1123,7 +1135,13 @@ def plot_profiling(ax, step_info_list: list[StepInfo], summary_info: dict, progr
11231135
11241136 if step_info .action is not None :
11251137 # Blue rectangle for agent_start to agent_stop
1126- add_patch (ax , prof .agent_start , prof .agent_stop , colors [10 ], labels .pop ("agent" , None ))
1138+ add_patch (
1139+ ax ,
1140+ prof .agent_start ,
1141+ prof .agent_stop ,
1142+ colors [10 ],
1143+ labels .pop ("agent" , None ),
1144+ )
11271145
11281146 # Black vertical bar at agent stop
11291147 ax .axvline (prof .agent_stop , color = "black" , linewidth = 3 )
0 commit comments