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 default_config , load_config_from_file , save_config_to_file , save_current_config , update_ui_from_config
42
43
from src .utils .utils import update_model_dropdown , get_latest_files , capture_screenshot
43
44
44
45
from dotenv import load_dotenv
@@ -588,7 +589,7 @@ async def close_global_browser():
588
589
await _global_browser .close ()
589
590
_global_browser = None
590
591
591
- def create_ui (theme_name = "Ocean" ):
592
+ def create_ui (config , theme_name = "Ocean" ):
592
593
css = """
593
594
.gradio-container {
594
595
max-width: 1200px !important;
@@ -634,33 +635,33 @@ def create_ui(theme_name="Ocean"):
634
635
agent_type = gr .Radio (
635
636
["org" , "custom" ],
636
637
label = "Agent Type" ,
637
- value = "custom" ,
638
+ value = config [ 'agent_type' ] ,
638
639
info = "Select the type of agent to use" ,
639
640
)
640
641
max_steps = gr .Slider (
641
642
minimum = 1 ,
642
643
maximum = 200 ,
643
- value = 100 ,
644
+ value = config [ 'max_steps' ] ,
644
645
step = 1 ,
645
646
label = "Max Run Steps" ,
646
647
info = "Maximum number of steps the agent will take" ,
647
648
)
648
649
max_actions_per_step = gr .Slider (
649
650
minimum = 1 ,
650
651
maximum = 20 ,
651
- value = 10 ,
652
+ value = config [ 'max_actions_per_step' ] ,
652
653
step = 1 ,
653
654
label = "Max Actions per Step" ,
654
655
info = "Maximum number of actions the agent will take per step" ,
655
656
)
656
657
use_vision = gr .Checkbox (
657
658
label = "Use Vision" ,
658
- value = True ,
659
+ value = config [ 'use_vision' ] ,
659
660
info = "Enable visual processing capabilities" ,
660
661
)
661
662
tool_call_in_content = gr .Checkbox (
662
663
label = "Use Tool Calls in Content" ,
663
- value = True ,
664
+ value = config [ 'tool_call_in_content' ] ,
664
665
info = "Enable Tool Calls in content" ,
665
666
)
666
667
@@ -669,35 +670,35 @@ def create_ui(theme_name="Ocean"):
669
670
llm_provider = gr .Dropdown (
670
671
choices = [provider for provider ,model in utils .model_names .items ()],
671
672
label = "LLM Provider" ,
672
- value = "openai" ,
673
+ value = config [ 'llm_provider' ] ,
673
674
info = "Select your preferred language model provider"
674
675
)
675
676
llm_model_name = gr .Dropdown (
676
677
label = "Model Name" ,
677
678
choices = utils .model_names ['openai' ],
678
- value = "gpt-4o" ,
679
+ value = config [ 'llm_model_name' ] ,
679
680
interactive = True ,
680
681
allow_custom_value = True , # Allow users to input custom model names
681
682
info = "Select a model from the dropdown or type a custom model name"
682
683
)
683
684
llm_temperature = gr .Slider (
684
685
minimum = 0.0 ,
685
686
maximum = 2.0 ,
686
- value = 1.0 ,
687
+ value = config [ 'llm_temperature' ] ,
687
688
step = 0.1 ,
688
689
label = "Temperature" ,
689
690
info = "Controls randomness in model outputs"
690
691
)
691
692
with gr .Row ():
692
693
llm_base_url = gr .Textbox (
693
694
label = "Base URL" ,
694
- value = '' ,
695
+ value = config [ 'llm_base_url' ] ,
695
696
info = "API endpoint URL (if required)"
696
697
)
697
698
llm_api_key = gr .Textbox (
698
699
label = "API Key" ,
699
700
type = "password" ,
700
- value = '' ,
701
+ value = config [ 'llm_api_key' ] ,
701
702
info = "Your API key (leave blank to use .env)"
702
703
)
703
704
@@ -706,62 +707,62 @@ def create_ui(theme_name="Ocean"):
706
707
with gr .Row ():
707
708
use_own_browser = gr .Checkbox (
708
709
label = "Use Own Browser" ,
709
- value = False ,
710
+ value = config [ 'use_own_browser' ] ,
710
711
info = "Use your existing browser instance" ,
711
712
)
712
713
keep_browser_open = gr .Checkbox (
713
714
label = "Keep Browser Open" ,
714
- value = os . getenv ( "CHROME_PERSISTENT_SESSION" , "False" ). lower () == "true" ,
715
+ value = config [ 'keep_browser_open' ] ,
715
716
info = "Keep Browser Open between Tasks" ,
716
717
)
717
718
headless = gr .Checkbox (
718
719
label = "Headless Mode" ,
719
- value = False ,
720
+ value = config [ 'headless' ] ,
720
721
info = "Run browser without GUI" ,
721
722
)
722
723
disable_security = gr .Checkbox (
723
724
label = "Disable Security" ,
724
- value = True ,
725
+ value = config [ 'disable_security' ] ,
725
726
info = "Disable browser security features" ,
726
727
)
727
728
enable_recording = gr .Checkbox (
728
729
label = "Enable Recording" ,
729
- value = True ,
730
+ value = config [ 'enable_recording' ] ,
730
731
info = "Enable saving browser recordings" ,
731
732
)
732
733
733
734
with gr .Row ():
734
735
window_w = gr .Number (
735
736
label = "Window Width" ,
736
- value = 1280 ,
737
+ value = config [ 'window_w' ] ,
737
738
info = "Browser window width" ,
738
739
)
739
740
window_h = gr .Number (
740
741
label = "Window Height" ,
741
- value = 1100 ,
742
+ value = config [ 'window_h' ] ,
742
743
info = "Browser window height" ,
743
744
)
744
745
745
746
save_recording_path = gr .Textbox (
746
747
label = "Recording Path" ,
747
748
placeholder = "e.g. ./tmp/record_videos" ,
748
- value = "./tmp/record_videos" ,
749
+ value = config [ 'save_recording_path' ] ,
749
750
info = "Path to save browser recordings" ,
750
751
interactive = True , # Allow editing only if recording is enabled
751
752
)
752
753
753
754
save_trace_path = gr .Textbox (
754
755
label = "Trace Path" ,
755
756
placeholder = "e.g. ./tmp/traces" ,
756
- value = "./tmp/traces" ,
757
+ value = config [ 'save_trace_path' ] ,
757
758
info = "Path to save Agent traces" ,
758
759
interactive = True ,
759
760
)
760
761
761
762
save_agent_history_path = gr .Textbox (
762
763
label = "Agent History Save Path" ,
763
764
placeholder = "e.g., ./tmp/agent_history" ,
764
- value = "./tmp/agent_history" ,
765
+ value = config [ 'save_agent_history_path' ] ,
765
766
info = "Specify the directory where agent history should be saved." ,
766
767
interactive = True ,
767
768
)
@@ -771,7 +772,7 @@ def create_ui(theme_name="Ocean"):
771
772
label = "Task Description" ,
772
773
lines = 4 ,
773
774
placeholder = "Enter your task here..." ,
774
- value = "go to google.com and type 'OpenAI' click search and give me the first url" ,
775
+ value = config [ 'task' ] ,
775
776
info = "Describe what you want the agent to do" ,
776
777
)
777
778
add_infos = gr .Textbox (
@@ -791,7 +792,48 @@ def create_ui(theme_name="Ocean"):
791
792
label = "Live Browser View" ,
792
793
)
793
794
794
- with gr .TabItem ("📊 Results" , id = 5 ):
795
+ with gr .TabItem ("📁 Configuration" , id = 5 ):
796
+ with gr .Group ():
797
+ config_file_input = gr .File (
798
+ label = "Load Config File" ,
799
+ file_types = [".pkl" ],
800
+ interactive = True
801
+ )
802
+
803
+ load_config_button = gr .Button ("Load Existing Config From File" , variant = "primary" )
804
+ save_config_button = gr .Button ("Save Current Config" , variant = "primary" )
805
+
806
+ config_status = gr .Textbox (
807
+ label = "Status" ,
808
+ lines = 2 ,
809
+ interactive = False
810
+ )
811
+
812
+ load_config_button .click (
813
+ fn = update_ui_from_config ,
814
+ inputs = [config_file_input ],
815
+ outputs = [
816
+ agent_type , max_steps , max_actions_per_step , use_vision , tool_call_in_content ,
817
+ llm_provider , llm_model_name , llm_temperature , llm_base_url , llm_api_key ,
818
+ use_own_browser , keep_browser_open , headless , disable_security , enable_recording ,
819
+ window_w , window_h , save_recording_path , save_trace_path , save_agent_history_path ,
820
+ task , config_status
821
+ ]
822
+ )
823
+
824
+ save_config_button .click (
825
+ fn = save_current_config ,
826
+ inputs = [
827
+ agent_type , max_steps , max_actions_per_step , use_vision , tool_call_in_content ,
828
+ llm_provider , llm_model_name , llm_temperature , llm_base_url , llm_api_key ,
829
+ use_own_browser , keep_browser_open , headless , disable_security ,
830
+ enable_recording , window_w , window_h , save_recording_path , save_trace_path ,
831
+ save_agent_history_path , task ,
832
+ ],
833
+ outputs = [config_status ]
834
+ )
835
+
836
+ with gr .TabItem ("📊 Results" , id = 6 ):
795
837
with gr .Group ():
796
838
797
839
recording_display = gr .Video (label = "Latest Recording" )
@@ -850,7 +892,7 @@ def create_ui(theme_name="Ocean"):
850
892
],
851
893
)
852
894
853
- with gr .TabItem ("🎥 Recordings" , id = 6 ):
895
+ with gr .TabItem ("🎥 Recordings" , id = 7 ):
854
896
def list_recordings (save_recording_path ):
855
897
if not os .path .exists (save_recording_path ):
856
898
return []
@@ -871,7 +913,7 @@ def list_recordings(save_recording_path):
871
913
872
914
recordings_gallery = gr .Gallery (
873
915
label = "Recordings" ,
874
- value = list_recordings ("./tmp/record_videos" ),
916
+ value = list_recordings (config [ 'save_recording_path' ] ),
875
917
columns = 3 ,
876
918
height = "auto" ,
877
919
object_fit = "contain"
@@ -911,7 +953,9 @@ def main():
911
953
parser .add_argument ("--dark-mode" , action = "store_true" , help = "Enable dark mode" )
912
954
args = parser .parse_args ()
913
955
914
- demo = create_ui (theme_name = args .theme )
956
+ config_dict = default_config ()
957
+
958
+ demo = create_ui (config_dict , theme_name = args .theme )
915
959
demo .launch (server_name = args .ip , server_port = args .port )
916
960
917
961
if __name__ == '__main__' :
0 commit comments