39
39
from src .browser .custom_context import BrowserContextConfig , CustomBrowserContext
40
40
from src .controller .custom_controller import CustomController
41
41
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
42
43
from src .utils .utils import update_model_dropdown , get_latest_files , capture_screenshot
43
44
44
45
from dotenv import load_dotenv
@@ -422,6 +423,7 @@ async def run_with_stream(
422
423
max_actions_per_step ,
423
424
tool_call_in_content
424
425
):
426
+ save_config_to_file (locals ())
425
427
global _global_agent_state
426
428
stream_vw = 80
427
429
stream_vh = int (80 * window_h // window_w )
@@ -588,7 +590,7 @@ async def close_global_browser():
588
590
await _global_browser .close ()
589
591
_global_browser = None
590
592
591
- def create_ui (theme_name = "Ocean" ):
593
+ def create_ui (config , theme_name = "Ocean" ):
592
594
css = """
593
595
.gradio-container {
594
596
max-width: 1200px !important;
@@ -634,33 +636,33 @@ def create_ui(theme_name="Ocean"):
634
636
agent_type = gr .Radio (
635
637
["org" , "custom" ],
636
638
label = "Agent Type" ,
637
- value = "custom" ,
639
+ value = config [ 'agent_type' ] ,
638
640
info = "Select the type of agent to use" ,
639
641
)
640
642
max_steps = gr .Slider (
641
643
minimum = 1 ,
642
644
maximum = 200 ,
643
- value = 100 ,
645
+ value = config [ 'max_steps' ] ,
644
646
step = 1 ,
645
647
label = "Max Run Steps" ,
646
648
info = "Maximum number of steps the agent will take" ,
647
649
)
648
650
max_actions_per_step = gr .Slider (
649
651
minimum = 1 ,
650
652
maximum = 20 ,
651
- value = 10 ,
653
+ value = config [ 'max_actions_per_step' ] ,
652
654
step = 1 ,
653
655
label = "Max Actions per Step" ,
654
656
info = "Maximum number of actions the agent will take per step" ,
655
657
)
656
658
use_vision = gr .Checkbox (
657
659
label = "Use Vision" ,
658
- value = True ,
660
+ value = config [ 'use_vision' ] ,
659
661
info = "Enable visual processing capabilities" ,
660
662
)
661
663
tool_call_in_content = gr .Checkbox (
662
664
label = "Use Tool Calls in Content" ,
663
- value = True ,
665
+ value = config [ 'tool_call_in_content' ] ,
664
666
info = "Enable Tool Calls in content" ,
665
667
)
666
668
@@ -669,35 +671,35 @@ def create_ui(theme_name="Ocean"):
669
671
llm_provider = gr .Dropdown (
670
672
choices = [provider for provider ,model in utils .model_names .items ()],
671
673
label = "LLM Provider" ,
672
- value = "openai" ,
674
+ value = config [ 'llm_provider' ] ,
673
675
info = "Select your preferred language model provider"
674
676
)
675
677
llm_model_name = gr .Dropdown (
676
678
label = "Model Name" ,
677
679
choices = utils .model_names ['openai' ],
678
- value = "gpt-4o" ,
680
+ value = config [ 'llm_model_name' ] ,
679
681
interactive = True ,
680
682
allow_custom_value = True , # Allow users to input custom model names
681
683
info = "Select a model from the dropdown or type a custom model name"
682
684
)
683
685
llm_temperature = gr .Slider (
684
686
minimum = 0.0 ,
685
687
maximum = 2.0 ,
686
- value = 1.0 ,
688
+ value = config [ 'llm_temperature' ] ,
687
689
step = 0.1 ,
688
690
label = "Temperature" ,
689
691
info = "Controls randomness in model outputs"
690
692
)
691
693
with gr .Row ():
692
694
llm_base_url = gr .Textbox (
693
695
label = "Base URL" ,
694
- value = '' ,
696
+ value = config [ 'llm_base_url' ] ,
695
697
info = "API endpoint URL (if required)"
696
698
)
697
699
llm_api_key = gr .Textbox (
698
700
label = "API Key" ,
699
701
type = "password" ,
700
- value = '' ,
702
+ value = config [ 'llm_api_key' ] ,
701
703
info = "Your API key (leave blank to use .env)"
702
704
)
703
705
@@ -706,62 +708,62 @@ def create_ui(theme_name="Ocean"):
706
708
with gr .Row ():
707
709
use_own_browser = gr .Checkbox (
708
710
label = "Use Own Browser" ,
709
- value = False ,
711
+ value = config [ 'use_own_browser' ] ,
710
712
info = "Use your existing browser instance" ,
711
713
)
712
714
keep_browser_open = gr .Checkbox (
713
715
label = "Keep Browser Open" ,
714
- value = os . getenv ( "CHROME_PERSISTENT_SESSION" , "False" ). lower () == "true" ,
716
+ value = config [ 'keep_browser_open' ] ,
715
717
info = "Keep Browser Open between Tasks" ,
716
718
)
717
719
headless = gr .Checkbox (
718
720
label = "Headless Mode" ,
719
- value = False ,
721
+ value = config [ 'headless' ] ,
720
722
info = "Run browser without GUI" ,
721
723
)
722
724
disable_security = gr .Checkbox (
723
725
label = "Disable Security" ,
724
- value = True ,
726
+ value = config [ 'disable_security' ] ,
725
727
info = "Disable browser security features" ,
726
728
)
727
729
enable_recording = gr .Checkbox (
728
730
label = "Enable Recording" ,
729
- value = True ,
731
+ value = config [ 'enable_recording' ] ,
730
732
info = "Enable saving browser recordings" ,
731
733
)
732
734
733
735
with gr .Row ():
734
736
window_w = gr .Number (
735
737
label = "Window Width" ,
736
- value = 1280 ,
738
+ value = config [ 'window_w' ] ,
737
739
info = "Browser window width" ,
738
740
)
739
741
window_h = gr .Number (
740
742
label = "Window Height" ,
741
- value = 1100 ,
743
+ value = config [ 'window_h' ] ,
742
744
info = "Browser window height" ,
743
745
)
744
746
745
747
save_recording_path = gr .Textbox (
746
748
label = "Recording Path" ,
747
749
placeholder = "e.g. ./tmp/record_videos" ,
748
- value = "./tmp/record_videos" ,
750
+ value = config [ 'save_recording_path' ] ,
749
751
info = "Path to save browser recordings" ,
750
752
interactive = True , # Allow editing only if recording is enabled
751
753
)
752
754
753
755
save_trace_path = gr .Textbox (
754
756
label = "Trace Path" ,
755
757
placeholder = "e.g. ./tmp/traces" ,
756
- value = "./tmp/traces" ,
758
+ value = config [ 'save_recording_path' ] ,
757
759
info = "Path to save Agent traces" ,
758
760
interactive = True ,
759
761
)
760
762
761
763
save_agent_history_path = gr .Textbox (
762
764
label = "Agent History Save Path" ,
763
765
placeholder = "e.g., ./tmp/agent_history" ,
764
- value = "./tmp/agent_history" ,
766
+ value = config [ 'save_agent_history_path' ] ,
765
767
info = "Specify the directory where agent history should be saved." ,
766
768
interactive = True ,
767
769
)
@@ -771,7 +773,7 @@ def create_ui(theme_name="Ocean"):
771
773
label = "Task Description" ,
772
774
lines = 4 ,
773
775
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' ] ,
775
777
info = "Describe what you want the agent to do" ,
776
778
)
777
779
add_infos = gr .Textbox (
@@ -871,7 +873,7 @@ def list_recordings(save_recording_path):
871
873
872
874
recordings_gallery = gr .Gallery (
873
875
label = "Recordings" ,
874
- value = list_recordings ("./tmp/record_videos" ),
876
+ value = list_recordings (config [ 'save_recording_path' ] ),
875
877
columns = 3 ,
876
878
height = "auto" ,
877
879
object_fit = "contain"
@@ -911,7 +913,10 @@ def main():
911
913
parser .add_argument ("--dark-mode" , action = "store_true" , help = "Enable dark mode" )
912
914
args = parser .parse_args ()
913
915
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 )
915
920
demo .launch (server_name = args .ip , server_port = args .port )
916
921
917
922
if __name__ == '__main__' :
0 commit comments