26
26
from src .browser .config import BrowserPersistenceConfig
27
27
from src .browser .custom_context import BrowserContextConfig
28
28
from src .controller .custom_controller import CustomController
29
+ from gradio .themes import Citrus , Default , Glass , Monochrome , Ocean , Origin , Soft , Base
29
30
from src .utils .utils import update_model_dropdown , get_latest_files , capture_screenshot
30
31
31
32
from dotenv import load_dotenv
@@ -202,8 +203,6 @@ async def run_custom_agent(
202
203
global _global_browser , _global_browser_context , _global_playwright
203
204
204
205
controller = CustomController ()
205
- playwright = None
206
- browser = None
207
206
persistence_config = BrowserPersistenceConfig .from_env ()
208
207
209
208
try :
@@ -463,8 +462,6 @@ async def cleanup():
463
462
finally :
464
463
asyncio .get_event_loop ().run_until_complete (cleanup ())
465
464
466
- from gradio .themes import Citrus , Default , Glass , Monochrome , Ocean , Origin , Soft , Base
467
-
468
465
# Define the theme map globally
469
466
theme_map = {
470
467
"Default" : Default (),
@@ -477,7 +474,6 @@ async def cleanup():
477
474
"Base" : Base ()
478
475
}
479
476
480
- # Create the Gradio UI
481
477
def create_ui (theme_name = "Ocean" ):
482
478
css = """
483
479
.gradio-container {
@@ -495,9 +491,19 @@ def create_ui(theme_name="Ocean"):
495
491
border-radius: 10px;
496
492
}
497
493
"""
494
+ js = """
495
+ function refresh() {
496
+ const url = new URL(window.location);
497
+ if (url.searchParams.get('__theme') !== 'dark') {
498
+ url.searchParams.set('__theme', 'dark');
499
+ window.location.href = url.href;
500
+ }
501
+ }
502
+ """
498
503
499
- with gr .Blocks (title = "Browser Use WebUI" , theme = theme_map [theme_name ], css = css ) as demo :
500
- # Header
504
+ with gr .Blocks (
505
+ title = "Browser Use WebUI" , theme = theme_map [theme_name ], css = css , js = js
506
+ ) as demo :
501
507
with gr .Row ():
502
508
gr .Markdown (
503
509
"""
@@ -673,7 +679,7 @@ def create_ui(theme_name="Ocean"):
673
679
model_thoughts_output = gr .Textbox (
674
680
label = "Model Thoughts" , lines = 3 , show_label = True
675
681
)
676
-
682
+
677
683
trace_file = gr .File (label = "Trace File" )
678
684
with gr .TabItem ("🎥 Recordings" , id = 6 ):
679
685
def list_recordings (save_recording_path ):
@@ -707,7 +713,7 @@ def list_recordings(save_recording_path):
707
713
fn = list_recordings ,
708
714
inputs = save_recording_path ,
709
715
outputs = recordings_gallery
710
- )
716
+ )
711
717
712
718
# Attach the callback to the LLM provider dropdown
713
719
llm_provider .change (
0 commit comments