Skip to content

Commit aec4779

Browse files
committed
feat: now reads configs from config.pkl file and show in the UI
1 parent e59917c commit aec4779

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

webui.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from src.browser.custom_context import BrowserContextConfig, CustomBrowserContext
4040
from src.controller.custom_controller import CustomController
4141
from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base
42+
from src.utils.default_config_settings import load_config_from_file, save_config_to_file
4243
from src.utils.utils import update_model_dropdown, get_latest_files, capture_screenshot
4344

4445
from dotenv import load_dotenv
@@ -422,6 +423,7 @@ async def run_with_stream(
422423
max_actions_per_step,
423424
tool_call_in_content
424425
):
426+
save_config_to_file(locals())
425427
global _global_agent_state
426428
stream_vw = 80
427429
stream_vh = int(80 * window_h // window_w)
@@ -588,7 +590,7 @@ async def close_global_browser():
588590
await _global_browser.close()
589591
_global_browser = None
590592

591-
def create_ui(theme_name="Ocean"):
593+
def create_ui(config, theme_name="Ocean"):
592594
css = """
593595
.gradio-container {
594596
max-width: 1200px !important;
@@ -634,33 +636,33 @@ def create_ui(theme_name="Ocean"):
634636
agent_type = gr.Radio(
635637
["org", "custom"],
636638
label="Agent Type",
637-
value="custom",
639+
value=config['agent_type'],
638640
info="Select the type of agent to use",
639641
)
640642
max_steps = gr.Slider(
641643
minimum=1,
642644
maximum=200,
643-
value=100,
645+
value=config['max_steps'],
644646
step=1,
645647
label="Max Run Steps",
646648
info="Maximum number of steps the agent will take",
647649
)
648650
max_actions_per_step = gr.Slider(
649651
minimum=1,
650652
maximum=20,
651-
value=10,
653+
value=config['max_actions_per_step'],
652654
step=1,
653655
label="Max Actions per Step",
654656
info="Maximum number of actions the agent will take per step",
655657
)
656658
use_vision = gr.Checkbox(
657659
label="Use Vision",
658-
value=True,
660+
value=config['use_vision'],
659661
info="Enable visual processing capabilities",
660662
)
661663
tool_call_in_content = gr.Checkbox(
662664
label="Use Tool Calls in Content",
663-
value=True,
665+
value=config['tool_call_in_content'],
664666
info="Enable Tool Calls in content",
665667
)
666668

@@ -669,35 +671,35 @@ def create_ui(theme_name="Ocean"):
669671
llm_provider = gr.Dropdown(
670672
choices=[provider for provider,model in utils.model_names.items()],
671673
label="LLM Provider",
672-
value="openai",
674+
value=config['llm_provider'],
673675
info="Select your preferred language model provider"
674676
)
675677
llm_model_name = gr.Dropdown(
676678
label="Model Name",
677679
choices=utils.model_names['openai'],
678-
value="gpt-4o",
680+
value=config['llm_model_name'],
679681
interactive=True,
680682
allow_custom_value=True, # Allow users to input custom model names
681683
info="Select a model from the dropdown or type a custom model name"
682684
)
683685
llm_temperature = gr.Slider(
684686
minimum=0.0,
685687
maximum=2.0,
686-
value=1.0,
688+
value=config['llm_temperature'],
687689
step=0.1,
688690
label="Temperature",
689691
info="Controls randomness in model outputs"
690692
)
691693
with gr.Row():
692694
llm_base_url = gr.Textbox(
693695
label="Base URL",
694-
value='',
696+
value=config['llm_base_url'],
695697
info="API endpoint URL (if required)"
696698
)
697699
llm_api_key = gr.Textbox(
698700
label="API Key",
699701
type="password",
700-
value='',
702+
value=config['llm_api_key'],
701703
info="Your API key (leave blank to use .env)"
702704
)
703705

@@ -706,62 +708,62 @@ def create_ui(theme_name="Ocean"):
706708
with gr.Row():
707709
use_own_browser = gr.Checkbox(
708710
label="Use Own Browser",
709-
value=False,
711+
value=config['use_own_browser'],
710712
info="Use your existing browser instance",
711713
)
712714
keep_browser_open = gr.Checkbox(
713715
label="Keep Browser Open",
714-
value=os.getenv("CHROME_PERSISTENT_SESSION", "False").lower() == "true",
716+
value=config['keep_browser_open'],
715717
info="Keep Browser Open between Tasks",
716718
)
717719
headless = gr.Checkbox(
718720
label="Headless Mode",
719-
value=False,
721+
value=config['headless'],
720722
info="Run browser without GUI",
721723
)
722724
disable_security = gr.Checkbox(
723725
label="Disable Security",
724-
value=True,
726+
value=config['disable_security'],
725727
info="Disable browser security features",
726728
)
727729
enable_recording = gr.Checkbox(
728730
label="Enable Recording",
729-
value=True,
731+
value=config['enable_recording'],
730732
info="Enable saving browser recordings",
731733
)
732734

733735
with gr.Row():
734736
window_w = gr.Number(
735737
label="Window Width",
736-
value=1280,
738+
value=config['window_w'],
737739
info="Browser window width",
738740
)
739741
window_h = gr.Number(
740742
label="Window Height",
741-
value=1100,
743+
value=config['window_h'],
742744
info="Browser window height",
743745
)
744746

745747
save_recording_path = gr.Textbox(
746748
label="Recording Path",
747749
placeholder="e.g. ./tmp/record_videos",
748-
value="./tmp/record_videos",
750+
value=config['save_recording_path'],
749751
info="Path to save browser recordings",
750752
interactive=True, # Allow editing only if recording is enabled
751753
)
752754

753755
save_trace_path = gr.Textbox(
754756
label="Trace Path",
755757
placeholder="e.g. ./tmp/traces",
756-
value="./tmp/traces",
758+
value=config['save_recording_path'],
757759
info="Path to save Agent traces",
758760
interactive=True,
759761
)
760762

761763
save_agent_history_path = gr.Textbox(
762764
label="Agent History Save Path",
763765
placeholder="e.g., ./tmp/agent_history",
764-
value="./tmp/agent_history",
766+
value=config['save_agent_history_path'],
765767
info="Specify the directory where agent history should be saved.",
766768
interactive=True,
767769
)
@@ -771,7 +773,7 @@ def create_ui(theme_name="Ocean"):
771773
label="Task Description",
772774
lines=4,
773775
placeholder="Enter your task here...",
774-
value="go to google.com and type 'OpenAI' click search and give me the first url",
776+
value=config['task'],
775777
info="Describe what you want the agent to do",
776778
)
777779
add_infos = gr.Textbox(
@@ -871,7 +873,7 @@ def list_recordings(save_recording_path):
871873

872874
recordings_gallery = gr.Gallery(
873875
label="Recordings",
874-
value=list_recordings("./tmp/record_videos"),
876+
value=list_recordings(config['save_recording_path']),
875877
columns=3,
876878
height="auto",
877879
object_fit="contain"
@@ -911,7 +913,10 @@ def main():
911913
parser.add_argument("--dark-mode", action="store_true", help="Enable dark mode")
912914
args = parser.parse_args()
913915

914-
demo = create_ui(theme_name=args.theme)
916+
# Ensure that the config file exists
917+
config_dict = load_config_from_file()
918+
919+
demo = create_ui(config_dict, theme_name=args.theme)
915920
demo.launch(server_name=args.ip, server_port=args.port)
916921

917922
if __name__ == '__main__':

0 commit comments

Comments
 (0)