Skip to content

Commit 9d73c89

Browse files
author
katiue
committed
reduce amount of changes for merge
1 parent f3c75a8 commit 9d73c89

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

webui.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from src.browser.config import BrowserPersistenceConfig
2727
from src.browser.custom_context import BrowserContextConfig
2828
from src.controller.custom_controller import CustomController
29+
from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base
2930
from src.utils.utils import update_model_dropdown, get_latest_files, capture_screenshot
3031

3132
from dotenv import load_dotenv
@@ -202,8 +203,6 @@ async def run_custom_agent(
202203
global _global_browser, _global_browser_context, _global_playwright
203204

204205
controller = CustomController()
205-
playwright = None
206-
browser = None
207206
persistence_config = BrowserPersistenceConfig.from_env()
208207

209208
try:
@@ -463,8 +462,6 @@ async def cleanup():
463462
finally:
464463
asyncio.get_event_loop().run_until_complete(cleanup())
465464

466-
from gradio.themes import Citrus, Default, Glass, Monochrome, Ocean, Origin, Soft, Base
467-
468465
# Define the theme map globally
469466
theme_map = {
470467
"Default": Default(),
@@ -477,7 +474,6 @@ async def cleanup():
477474
"Base": Base()
478475
}
479476

480-
# Create the Gradio UI
481477
def create_ui(theme_name="Ocean"):
482478
css = """
483479
.gradio-container {
@@ -495,9 +491,19 @@ def create_ui(theme_name="Ocean"):
495491
border-radius: 10px;
496492
}
497493
"""
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+
"""
498503

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:
501507
with gr.Row():
502508
gr.Markdown(
503509
"""
@@ -673,7 +679,7 @@ def create_ui(theme_name="Ocean"):
673679
model_thoughts_output = gr.Textbox(
674680
label="Model Thoughts", lines=3, show_label=True
675681
)
676-
682+
677683
trace_file = gr.File(label="Trace File")
678684
with gr.TabItem("🎥 Recordings", id=6):
679685
def list_recordings(save_recording_path):
@@ -707,7 +713,7 @@ def list_recordings(save_recording_path):
707713
fn=list_recordings,
708714
inputs=save_recording_path,
709715
outputs=recordings_gallery
710-
)
716+
)
711717

712718
# Attach the callback to the LLM provider dropdown
713719
llm_provider.change(

0 commit comments

Comments
 (0)