From e59917c5ad64f4b8044a8293cec475af48825608 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 20 Jan 2025 16:55:12 +0330 Subject: [PATCH 01/11] feat: add .config.pkl file to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2d83410..a3f269d 100644 --- a/.gitignore +++ b/.gitignore @@ -184,3 +184,6 @@ AgentHistoryList.json # For Docker data/ + +# For Config Files (Current Settings) +.config.pkl From aec4779bd27945849e3cbc952dc46c9eb0b25c64 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 20 Jan 2025 16:56:37 +0330 Subject: [PATCH 02/11] feat: now reads configs from config.pkl file and show in the UI --- webui.py | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/webui.py b/webui.py index b7acffe..d4e2996 100644 --- a/webui.py +++ b/webui.py @@ -39,6 +39,7 @@ from src.browser.config import BrowserPersistenceConfig from src.browser.custom_context import BrowserContextConfig, CustomBrowserContext from src.controller.custom_controller import CustomController from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base +from src.utils.default_config_settings import load_config_from_file, save_config_to_file from src.utils.utils import update_model_dropdown, get_latest_files, capture_screenshot from dotenv import load_dotenv @@ -422,6 +423,7 @@ async def run_with_stream( max_actions_per_step, tool_call_in_content ): + save_config_to_file(locals()) global _global_agent_state stream_vw = 80 stream_vh = int(80 * window_h // window_w) @@ -588,7 +590,7 @@ async def close_global_browser(): await _global_browser.close() _global_browser = None -def create_ui(theme_name="Ocean"): +def create_ui(config, theme_name="Ocean"): css = """ .gradio-container { max-width: 1200px !important; @@ -634,13 +636,13 @@ def create_ui(theme_name="Ocean"): agent_type = gr.Radio( ["org", "custom"], label="Agent Type", - value="custom", + value=config['agent_type'], info="Select the type of agent to use", ) max_steps = gr.Slider( minimum=1, maximum=200, - value=100, + value=config['max_steps'], step=1, label="Max Run Steps", info="Maximum number of steps the agent will take", @@ -648,19 +650,19 @@ def create_ui(theme_name="Ocean"): max_actions_per_step = gr.Slider( minimum=1, maximum=20, - value=10, + value=config['max_actions_per_step'], step=1, label="Max Actions per Step", info="Maximum number of actions the agent will take per step", ) use_vision = gr.Checkbox( label="Use Vision", - value=True, + value=config['use_vision'], info="Enable visual processing capabilities", ) tool_call_in_content = gr.Checkbox( label="Use Tool Calls in Content", - value=True, + value=config['tool_call_in_content'], info="Enable Tool Calls in content", ) @@ -669,13 +671,13 @@ def create_ui(theme_name="Ocean"): llm_provider = gr.Dropdown( choices=[provider for provider,model in utils.model_names.items()], label="LLM Provider", - value="openai", + value=config['llm_provider'], info="Select your preferred language model provider" ) llm_model_name = gr.Dropdown( label="Model Name", choices=utils.model_names['openai'], - value="gpt-4o", + value=config['llm_model_name'], interactive=True, allow_custom_value=True, # Allow users to input custom model names info="Select a model from the dropdown or type a custom model name" @@ -683,7 +685,7 @@ def create_ui(theme_name="Ocean"): llm_temperature = gr.Slider( minimum=0.0, maximum=2.0, - value=1.0, + value=config['llm_temperature'], step=0.1, label="Temperature", info="Controls randomness in model outputs" @@ -691,13 +693,13 @@ def create_ui(theme_name="Ocean"): with gr.Row(): llm_base_url = gr.Textbox( label="Base URL", - value='', + value=config['llm_base_url'], info="API endpoint URL (if required)" ) llm_api_key = gr.Textbox( label="API Key", type="password", - value='', + value=config['llm_api_key'], info="Your API key (leave blank to use .env)" ) @@ -706,46 +708,46 @@ def create_ui(theme_name="Ocean"): with gr.Row(): use_own_browser = gr.Checkbox( label="Use Own Browser", - value=False, + value=config['use_own_browser'], info="Use your existing browser instance", ) keep_browser_open = gr.Checkbox( label="Keep Browser Open", - value=os.getenv("CHROME_PERSISTENT_SESSION", "False").lower() == "true", + value=config['keep_browser_open'], info="Keep Browser Open between Tasks", ) headless = gr.Checkbox( label="Headless Mode", - value=False, + value=config['headless'], info="Run browser without GUI", ) disable_security = gr.Checkbox( label="Disable Security", - value=True, + value=config['disable_security'], info="Disable browser security features", ) enable_recording = gr.Checkbox( label="Enable Recording", - value=True, + value=config['enable_recording'], info="Enable saving browser recordings", ) with gr.Row(): window_w = gr.Number( label="Window Width", - value=1280, + value=config['window_w'], info="Browser window width", ) window_h = gr.Number( label="Window Height", - value=1100, + value=config['window_h'], info="Browser window height", ) save_recording_path = gr.Textbox( label="Recording Path", placeholder="e.g. ./tmp/record_videos", - value="./tmp/record_videos", + value=config['save_recording_path'], info="Path to save browser recordings", interactive=True, # Allow editing only if recording is enabled ) @@ -753,7 +755,7 @@ def create_ui(theme_name="Ocean"): save_trace_path = gr.Textbox( label="Trace Path", placeholder="e.g. ./tmp/traces", - value="./tmp/traces", + value=config['save_recording_path'], info="Path to save Agent traces", interactive=True, ) @@ -761,7 +763,7 @@ def create_ui(theme_name="Ocean"): save_agent_history_path = gr.Textbox( label="Agent History Save Path", placeholder="e.g., ./tmp/agent_history", - value="./tmp/agent_history", + value=config['save_agent_history_path'], info="Specify the directory where agent history should be saved.", interactive=True, ) @@ -771,7 +773,7 @@ def create_ui(theme_name="Ocean"): label="Task Description", lines=4, placeholder="Enter your task here...", - value="go to google.com and type 'OpenAI' click search and give me the first url", + value=config['task'], info="Describe what you want the agent to do", ) add_infos = gr.Textbox( @@ -871,7 +873,7 @@ def create_ui(theme_name="Ocean"): recordings_gallery = gr.Gallery( label="Recordings", - value=list_recordings("./tmp/record_videos"), + value=list_recordings(config['save_recording_path']), columns=3, height="auto", object_fit="contain" @@ -911,7 +913,10 @@ def main(): parser.add_argument("--dark-mode", action="store_true", help="Enable dark mode") args = parser.parse_args() - demo = create_ui(theme_name=args.theme) + # Ensure that the config file exists + config_dict = load_config_from_file() + + demo = create_ui(config_dict, theme_name=args.theme) demo.launch(server_name=args.ip, server_port=args.port) if __name__ == '__main__': From 0f50b3ff729d11bb8bbbca5c10f2eb006c29dbd5 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 20 Jan 2025 16:58:54 +0330 Subject: [PATCH 03/11] feat: implemented save to file and load from file functionality --- src/utils/default_config_settings.py | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/utils/default_config_settings.py diff --git a/src/utils/default_config_settings.py b/src/utils/default_config_settings.py new file mode 100644 index 0000000..d09ea7f --- /dev/null +++ b/src/utils/default_config_settings.py @@ -0,0 +1,40 @@ +import os +import pickle + + +def load_config_from_file(file_path: str='./.config.pkl',) -> dict: + try: + with open(file_path, 'rb') as file: + loaded_config = pickle.load(file) + except FileNotFoundError as FNFE: + from dotenv import load_dotenv + load_dotenv() + return { + "agent_type": "custom", + "max_steps": 100, + "max_actions_per_step": 10, + "use_vision": True, + "tool_call_in_content": True, + "llm_provider": "openai", + "llm_model_name": "gpt-4o", + "llm_temperature": 1.0, + "llm_base_url": '', + "llm_api_key": '', + "use_own_browser": False, + "keep_browser_open": os.getenv("CHROME_PERSISTENT_SESSION", "False").lower() == "true", + "headless": False, + "disable_security": True, + "enable_recording": True, + "window_w": 1280, + "window_h": 1100, + "save_recording_path": "./tmp/record_videos", + "save_trace_path": "./tmp/traces", + "save_agent_history_path": "./tmp/agent_history", + "task": "go to google.com and type 'OpenAI' click search and give me the first url", + } + return loaded_config + + +def save_config_to_file(config, file_path: str='./.config.pkl',) -> None: + with open(file_path, 'wb') as file: + pickle.dump(config, file) From b540b35823d6c043427027e1cdb23f2bc28cacfb Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 10:21:46 +0330 Subject: [PATCH 04/11] refactor: remove unnecessary comment --- webui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/webui.py b/webui.py index d4e2996..f7bf54d 100644 --- a/webui.py +++ b/webui.py @@ -913,7 +913,6 @@ def main(): parser.add_argument("--dark-mode", action="store_true", help="Enable dark mode") args = parser.parse_args() - # Ensure that the config file exists config_dict = load_config_from_file() demo = create_ui(config_dict, theme_name=args.theme) From 2b2edc33912615ab5a6504c48551d57f2ffc42b9 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 11:06:57 +0330 Subject: [PATCH 05/11] feat: load and save functions to follow uuid format --- src/utils/default_config_settings.py | 48 +++++++++------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/utils/default_config_settings.py b/src/utils/default_config_settings.py index d09ea7f..3af4dc2 100644 --- a/src/utils/default_config_settings.py +++ b/src/utils/default_config_settings.py @@ -1,40 +1,22 @@ import os import pickle +import uuid -def load_config_from_file(file_path: str='./.config.pkl',) -> dict: +def load_config_from_file(config_file): + """Load settings from a UUID.pkl file.""" try: - with open(file_path, 'rb') as file: - loaded_config = pickle.load(file) - except FileNotFoundError as FNFE: - from dotenv import load_dotenv - load_dotenv() - return { - "agent_type": "custom", - "max_steps": 100, - "max_actions_per_step": 10, - "use_vision": True, - "tool_call_in_content": True, - "llm_provider": "openai", - "llm_model_name": "gpt-4o", - "llm_temperature": 1.0, - "llm_base_url": '', - "llm_api_key": '', - "use_own_browser": False, - "keep_browser_open": os.getenv("CHROME_PERSISTENT_SESSION", "False").lower() == "true", - "headless": False, - "disable_security": True, - "enable_recording": True, - "window_w": 1280, - "window_h": 1100, - "save_recording_path": "./tmp/record_videos", - "save_trace_path": "./tmp/traces", - "save_agent_history_path": "./tmp/agent_history", - "task": "go to google.com and type 'OpenAI' click search and give me the first url", - } - return loaded_config + with open(config_file, 'rb') as f: + settings = pickle.load(f) + return settings + except Exception as e: + return f"Error loading configuration: {str(e)}" -def save_config_to_file(config, file_path: str='./.config.pkl',) -> None: - with open(file_path, 'wb') as file: - pickle.dump(config, file) +def save_config_to_file(settings, save_dir="./tmp/webui_settings"): + """Save the current settings to a UUID.pkl file with a UUID name.""" + os.makedirs(save_dir, exist_ok=True) + config_file = os.path.join(save_dir, f"{uuid.uuid4()}.pkl") + with open(config_file, 'wb') as f: + pickle.dump(settings, f) + return f"Configuration saved to {config_file}" From 048a344a5aaeee181d3c0bf9bba2c46b2ad958f4 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 11:51:10 +0330 Subject: [PATCH 06/11] feat: startup default configuration with default values --- default_config.pkl | Bin 0 -> 554 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 default_config.pkl diff --git a/default_config.pkl b/default_config.pkl new file mode 100644 index 0000000000000000000000000000000000000000..7d7b0c60df90e56470bd5d6e3e785ec025354be3 GIT binary patch literal 554 zcmY*Wv2GMG5Ivy-g(HxlL`sRf&~Rz!5mgi=Q9i-)*~6}Nw#Tw(Z@D5;N|0O*|H&s{ z?~*8S<$3RE-kX_+<)2Tl7Sp@u&t;`L2qbAAfy)~`WJ1s7tye!~CWx7@O*w6q(qu7Y z86iy!U$4q)$RKw%SAu_)Q$lo7E9ayQQe&Xnx#EY;c^MP#tbtTbFhWq4%ZG-0G~i@V zzS(z?zI;V4M~xxy)l1QkfG@xOog>f9Hmdp#$#Ge5dDp}$TDgTi_wUP53x#8ln}lPo zj=#&tEkJy%W%IA#K@Z9}$hrQHjm>J~KxWWGvb3+Uk88>XCD53R4PC_!MjH%{a^%~^ z>!+&c+nZ%M$!hmZEu*5I%gOqJe7u;O)Lj|CTnC)Al$3`5y2DvFK~-=z3Fh1MwjL$z zUp9O}aaoeeTP{}}3PRB#b`I7Wy->l3c3g3OSI7Q-buP5CdMh%hr2C2P><)wnK|P2c LHf0iRwZr-!oCel5 literal 0 HcmV?d00001 From 704ea646cafc1b9806d6c63d3c8e21801044c672 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 11:51:55 +0330 Subject: [PATCH 07/11] feat: added configuration tab with load config from file and save current config to a file buttons with status --- webui.py | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/webui.py b/webui.py index f7bf54d..74fef9e 100644 --- a/webui.py +++ b/webui.py @@ -793,7 +793,118 @@ def create_ui(config, theme_name="Ocean"): label="Live Browser View", ) - with gr.TabItem("📊 Results", id=5): + with gr.TabItem("📁 Configuration", id=5): + with gr.Group(): + config_file_input = gr.File( + label="Load Config File", + file_types=[".pkl"], + interactive=True + ) + + load_config_button = gr.Button("Load Existing Config From File", variant="primary") + save_config_button = gr.Button("Save Current Config", variant="primary") + + config_status = gr.Textbox( + label="Status", + lines=2, + interactive=False + ) + + def update_ui_from_config(config_file): + if config_file is not None: + loaded_config = load_config_from_file(config_file.name) + if isinstance(loaded_config, dict): + return ( + gr.update(value=loaded_config.get("agent_type", "custom")), + gr.update(value=loaded_config.get("max_steps", 100)), + gr.update(value=loaded_config.get("max_actions_per_step", 10)), + gr.update(value=loaded_config.get("use_vision", True)), + gr.update(value=loaded_config.get("tool_call_in_content", True)), + gr.update(value=loaded_config.get("llm_provider", "openai")), + gr.update(value=loaded_config.get("llm_model_name", "gpt-4o")), + gr.update(value=loaded_config.get("llm_temperature", 1.0)), + gr.update(value=loaded_config.get("llm_base_url", "")), + gr.update(value=loaded_config.get("llm_api_key", "")), + gr.update(value=loaded_config.get("use_own_browser", False)), + gr.update(value=loaded_config.get("keep_browser_open", False)), + gr.update(value=loaded_config.get("headless", False)), + gr.update(value=loaded_config.get("disable_security", True)), + gr.update(value=loaded_config.get("enable_recording", True)), + gr.update(value=loaded_config.get("window_w", 1280)), + gr.update(value=loaded_config.get("window_h", 1100)), + gr.update(value=loaded_config.get("save_recording_path", "./tmp/record_videos")), + gr.update(value=loaded_config.get("save_trace_path", "./tmp/traces")), + gr.update(value=loaded_config.get("save_agent_history_path", "./tmp/agent_history")), + gr.update(value=loaded_config.get("task", "")), + "Configuration loaded successfully." + ) + else: + return ( + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), "Error: Invalid configuration file." + ) + return ( + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), "No file selected." + ) + + load_config_button.click( + fn=update_ui_from_config, + inputs=[config_file_input], + outputs=[ + agent_type, max_steps, max_actions_per_step, use_vision, tool_call_in_content, + llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, + use_own_browser, keep_browser_open, headless, disable_security, enable_recording, + window_w, window_h, save_recording_path, save_trace_path, save_agent_history_path, + task, config_status + ] + ) + + def save_current_config(*args): + current_config = { + "agent_type": args[0], + "max_steps": args[1], + "max_actions_per_step": args[2], + "use_vision": args[3], + "tool_call_in_content": args[4], + "llm_provider": args[5], + "llm_model_name": args[6], + "llm_temperature": args[7], + "llm_base_url": args[8], + "llm_api_key": args[9], + "use_own_browser": args[10], + "keep_browser_open": args[11], + "headless": args[12], + "disable_security": args[13], + "enable_recording": args[14], + "window_w": args[15], + "window_h": args[16], + "save_recording_path": args[17], + "save_trace_path": args[18], + "save_agent_history_path": args[19], + "task": args[20], + } + return save_config_to_file(current_config) + + save_config_button.click( + fn=save_current_config, + inputs=[ + agent_type, max_steps, max_actions_per_step, use_vision, tool_call_in_content, + llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key, + use_own_browser, keep_browser_open, headless, disable_security, + enable_recording, window_w, window_h, save_recording_path, save_trace_path, + save_agent_history_path, task, + ], + outputs=[config_status] + ) + + with gr.TabItem("📊 Results", id=6): with gr.Group(): recording_display = gr.Video(label="Latest Recording") @@ -852,7 +963,7 @@ def create_ui(config, theme_name="Ocean"): ], ) - with gr.TabItem("🎥 Recordings", id=6): + with gr.TabItem("🎥 Recordings", id=7): def list_recordings(save_recording_path): if not os.path.exists(save_recording_path): return [] @@ -913,7 +1024,7 @@ def main(): parser.add_argument("--dark-mode", action="store_true", help="Enable dark mode") args = parser.parse_args() - config_dict = load_config_from_file() + config_dict = load_config_from_file("./default_config.pkl") or {} demo = create_ui(config_dict, theme_name=args.theme) demo.launch(server_name=args.ip, server_port=args.port) From 2d2aa0d6893f77a5c99d5eab223b4646c94d71d1 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 11:58:49 +0330 Subject: [PATCH 08/11] feat: add default config to load from hard-code instead of a file --- default_config.pkl | Bin 554 -> 0 bytes src/utils/default_config_settings.py | 27 +++++++++++++++++++++++++++ webui.py | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) delete mode 100644 default_config.pkl diff --git a/default_config.pkl b/default_config.pkl deleted file mode 100644 index 7d7b0c60df90e56470bd5d6e3e785ec025354be3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 554 zcmY*Wv2GMG5Ivy-g(HxlL`sRf&~Rz!5mgi=Q9i-)*~6}Nw#Tw(Z@D5;N|0O*|H&s{ z?~*8S<$3RE-kX_+<)2Tl7Sp@u&t;`L2qbAAfy)~`WJ1s7tye!~CWx7@O*w6q(qu7Y z86iy!U$4q)$RKw%SAu_)Q$lo7E9ayQQe&Xnx#EY;c^MP#tbtTbFhWq4%ZG-0G~i@V zzS(z?zI;V4M~xxy)l1QkfG@xOog>f9Hmdp#$#Ge5dDp}$TDgTi_wUP53x#8ln}lPo zj=#&tEkJy%W%IA#K@Z9}$hrQHjm>J~KxWWGvb3+Uk88>XCD53R4PC_!MjH%{a^%~^ z>!+&c+nZ%M$!hmZEu*5I%gOqJe7u;O)Lj|CTnC)Al$3`5y2DvFK~-=z3Fh1MwjL$z zUp9O}aaoeeTP{}}3PRB#b`I7Wy->l3c3g3OSI7Q-buP5CdMh%hr2C2P><)wnK|P2c LHf0iRwZr-!oCel5 diff --git a/src/utils/default_config_settings.py b/src/utils/default_config_settings.py index 3af4dc2..4853ebf 100644 --- a/src/utils/default_config_settings.py +++ b/src/utils/default_config_settings.py @@ -3,6 +3,33 @@ import pickle import uuid +def default_config(): + """Prepare the default configuration""" + return { + "agent_type": "custom", + "max_steps": 100, + "max_actions_per_step": 10, + "use_vision": True, + "tool_call_in_content": True, + "llm_provider": "openai", + "llm_model_name": "gpt-4o", + "llm_temperature": 1.0, + "llm_base_url": "", + "llm_api_key": "", + "use_own_browser": False, + "keep_browser_open": False, + "headless": False, + "disable_security": True, + "enable_recording": True, + "window_w": 1280, + "window_h": 1100, + "save_recording_path": "./tmp/record_videos", + "save_trace_path": "./tmp/traces", + "save_agent_history_path": "./tmp/agent_history", + "task": "go to google.com and type 'OpenAI' click search and give me the first url", + } + + def load_config_from_file(config_file): """Load settings from a UUID.pkl file.""" try: diff --git a/webui.py b/webui.py index 74fef9e..6e0d14a 100644 --- a/webui.py +++ b/webui.py @@ -39,7 +39,7 @@ from src.browser.config import BrowserPersistenceConfig from src.browser.custom_context import BrowserContextConfig, CustomBrowserContext from src.controller.custom_controller import CustomController from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base -from src.utils.default_config_settings import load_config_from_file, save_config_to_file +from src.utils.default_config_settings import default_config, load_config_from_file, save_config_to_file from src.utils.utils import update_model_dropdown, get_latest_files, capture_screenshot from dotenv import load_dotenv @@ -1024,7 +1024,7 @@ def main(): parser.add_argument("--dark-mode", action="store_true", help="Enable dark mode") args = parser.parse_args() - config_dict = load_config_from_file("./default_config.pkl") or {} + config_dict = default_config() demo = create_ui(config_dict, theme_name=args.theme) demo.launch(server_name=args.ip, server_port=args.port) From 0e152d557d6b257d0f7cd48ff3c07b64eb1a52c4 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 12:00:18 +0330 Subject: [PATCH 09/11] fix: remove previous logic to save the setting by running the agent --- webui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/webui.py b/webui.py index 6e0d14a..4d36aa8 100644 --- a/webui.py +++ b/webui.py @@ -423,7 +423,6 @@ async def run_with_stream( max_actions_per_step, tool_call_in_content ): - save_config_to_file(locals()) global _global_agent_state stream_vw = 80 stream_vh = int(80 * window_h // window_w) From dce50eb01bec76db8a3af02399a2cf02f5f6f389 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 12:08:19 +0330 Subject: [PATCH 10/11] refactor: moved functions to utils for more readability --- src/utils/default_config_settings.py | 73 ++++++++++++++++++++++++++++ webui.py | 72 +-------------------------- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/utils/default_config_settings.py b/src/utils/default_config_settings.py index 4853ebf..b4c08cf 100644 --- a/src/utils/default_config_settings.py +++ b/src/utils/default_config_settings.py @@ -1,6 +1,7 @@ import os import pickle import uuid +import gradio as gr def default_config(): @@ -47,3 +48,75 @@ def save_config_to_file(settings, save_dir="./tmp/webui_settings"): with open(config_file, 'wb') as f: pickle.dump(settings, f) return f"Configuration saved to {config_file}" + + +def save_current_config(*args): + current_config = { + "agent_type": args[0], + "max_steps": args[1], + "max_actions_per_step": args[2], + "use_vision": args[3], + "tool_call_in_content": args[4], + "llm_provider": args[5], + "llm_model_name": args[6], + "llm_temperature": args[7], + "llm_base_url": args[8], + "llm_api_key": args[9], + "use_own_browser": args[10], + "keep_browser_open": args[11], + "headless": args[12], + "disable_security": args[13], + "enable_recording": args[14], + "window_w": args[15], + "window_h": args[16], + "save_recording_path": args[17], + "save_trace_path": args[18], + "save_agent_history_path": args[19], + "task": args[20], + } + return save_config_to_file(current_config) + + +def update_ui_from_config(config_file): + if config_file is not None: + loaded_config = load_config_from_file(config_file.name) + if isinstance(loaded_config, dict): + return ( + gr.update(value=loaded_config.get("agent_type", "custom")), + gr.update(value=loaded_config.get("max_steps", 100)), + gr.update(value=loaded_config.get("max_actions_per_step", 10)), + gr.update(value=loaded_config.get("use_vision", True)), + gr.update(value=loaded_config.get("tool_call_in_content", True)), + gr.update(value=loaded_config.get("llm_provider", "openai")), + gr.update(value=loaded_config.get("llm_model_name", "gpt-4o")), + gr.update(value=loaded_config.get("llm_temperature", 1.0)), + gr.update(value=loaded_config.get("llm_base_url", "")), + gr.update(value=loaded_config.get("llm_api_key", "")), + gr.update(value=loaded_config.get("use_own_browser", False)), + gr.update(value=loaded_config.get("keep_browser_open", False)), + gr.update(value=loaded_config.get("headless", False)), + gr.update(value=loaded_config.get("disable_security", True)), + gr.update(value=loaded_config.get("enable_recording", True)), + gr.update(value=loaded_config.get("window_w", 1280)), + gr.update(value=loaded_config.get("window_h", 1100)), + gr.update(value=loaded_config.get("save_recording_path", "./tmp/record_videos")), + gr.update(value=loaded_config.get("save_trace_path", "./tmp/traces")), + gr.update(value=loaded_config.get("save_agent_history_path", "./tmp/agent_history")), + gr.update(value=loaded_config.get("task", "")), + "Configuration loaded successfully." + ) + else: + return ( + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), "Error: Invalid configuration file." + ) + return ( + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), + gr.update(), "No file selected." + ) diff --git a/webui.py b/webui.py index 4d36aa8..579a09f 100644 --- a/webui.py +++ b/webui.py @@ -39,7 +39,7 @@ from src.browser.config import BrowserPersistenceConfig from src.browser.custom_context import BrowserContextConfig, CustomBrowserContext from src.controller.custom_controller import CustomController from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base -from src.utils.default_config_settings import default_config, load_config_from_file, save_config_to_file +from src.utils.default_config_settings import default_config, load_config_from_file, save_config_to_file, save_current_config, update_ui_from_config from src.utils.utils import update_model_dropdown, get_latest_files, capture_screenshot from dotenv import load_dotenv @@ -809,50 +809,6 @@ def create_ui(config, theme_name="Ocean"): interactive=False ) - def update_ui_from_config(config_file): - if config_file is not None: - loaded_config = load_config_from_file(config_file.name) - if isinstance(loaded_config, dict): - return ( - gr.update(value=loaded_config.get("agent_type", "custom")), - gr.update(value=loaded_config.get("max_steps", 100)), - gr.update(value=loaded_config.get("max_actions_per_step", 10)), - gr.update(value=loaded_config.get("use_vision", True)), - gr.update(value=loaded_config.get("tool_call_in_content", True)), - gr.update(value=loaded_config.get("llm_provider", "openai")), - gr.update(value=loaded_config.get("llm_model_name", "gpt-4o")), - gr.update(value=loaded_config.get("llm_temperature", 1.0)), - gr.update(value=loaded_config.get("llm_base_url", "")), - gr.update(value=loaded_config.get("llm_api_key", "")), - gr.update(value=loaded_config.get("use_own_browser", False)), - gr.update(value=loaded_config.get("keep_browser_open", False)), - gr.update(value=loaded_config.get("headless", False)), - gr.update(value=loaded_config.get("disable_security", True)), - gr.update(value=loaded_config.get("enable_recording", True)), - gr.update(value=loaded_config.get("window_w", 1280)), - gr.update(value=loaded_config.get("window_h", 1100)), - gr.update(value=loaded_config.get("save_recording_path", "./tmp/record_videos")), - gr.update(value=loaded_config.get("save_trace_path", "./tmp/traces")), - gr.update(value=loaded_config.get("save_agent_history_path", "./tmp/agent_history")), - gr.update(value=loaded_config.get("task", "")), - "Configuration loaded successfully." - ) - else: - return ( - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), "Error: Invalid configuration file." - ) - return ( - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), - gr.update(), "No file selected." - ) - load_config_button.click( fn=update_ui_from_config, inputs=[config_file_input], @@ -865,32 +821,6 @@ def create_ui(config, theme_name="Ocean"): ] ) - def save_current_config(*args): - current_config = { - "agent_type": args[0], - "max_steps": args[1], - "max_actions_per_step": args[2], - "use_vision": args[3], - "tool_call_in_content": args[4], - "llm_provider": args[5], - "llm_model_name": args[6], - "llm_temperature": args[7], - "llm_base_url": args[8], - "llm_api_key": args[9], - "use_own_browser": args[10], - "keep_browser_open": args[11], - "headless": args[12], - "disable_security": args[13], - "enable_recording": args[14], - "window_w": args[15], - "window_h": args[16], - "save_recording_path": args[17], - "save_trace_path": args[18], - "save_agent_history_path": args[19], - "task": args[20], - } - return save_config_to_file(current_config) - save_config_button.click( fn=save_current_config, inputs=[ From b616f2d79ee54411bd1f95b0fbfb6e72286485ac Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Wed, 22 Jan 2025 12:25:11 +0330 Subject: [PATCH 11/11] hotfix: trace path was being shown as recording path --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 579a09f..2e3570b 100644 --- a/webui.py +++ b/webui.py @@ -754,7 +754,7 @@ def create_ui(config, theme_name="Ocean"): save_trace_path = gr.Textbox( label="Trace Path", placeholder="e.g. ./tmp/traces", - value=config['save_recording_path'], + value=config['save_trace_path'], info="Path to save Agent traces", interactive=True, )