Skip to content

Commit 7a09983

Browse files
Update webui.py
1 parent d5823a5 commit 7a09983

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

webui.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async def run_custom_agent(
225225
import argparse
226226
import gradio as gr
227227
from gradio.themes import Base, Default, Soft, Monochrome, Glass, Origin, Citrus, Ocean
228-
import os
228+
import os, glob
229229

230230
# Define the theme map globally
231231
theme_map = {
@@ -238,7 +238,7 @@ async def run_custom_agent(
238238
"Ocean": Ocean()
239239
}
240240

241-
def create_ui(theme_name="Citrus"):
241+
def create_ui():
242242
"""Create the UI with the specified theme"""
243243
# Enhanced styling for better visual appeal
244244
css = """
@@ -258,7 +258,7 @@ def create_ui(theme_name="Citrus"):
258258
}
259259
"""
260260

261-
with gr.Blocks(title="Browser Use WebUI", theme=theme_map[theme_name], css=css) as demo:
261+
with gr.Blocks(title="Browser Use WebUI", theme=theme_map["Ocean"], css=css) as demo:
262262
with gr.Row():
263263
gr.Markdown(
264264
"""
@@ -268,15 +268,6 @@ def create_ui(theme_name="Citrus"):
268268
elem_classes=["header-text"]
269269
)
270270

271-
# Quick access theme switcher at the top
272-
with gr.Row(elem_classes=["theme-section"]):
273-
theme_dropdown = gr.Dropdown(
274-
choices=list(theme_map.keys()),
275-
value=theme_name,
276-
label="🎨 Quick Theme Switch",
277-
container=False
278-
)
279-
280271
with gr.Tabs() as tabs:
281272
with gr.TabItem("🤖 Agent Settings", id=1):
282273
with gr.Group():
@@ -303,7 +294,7 @@ def create_ui(theme_name="Citrus"):
303294
with gr.TabItem("🔧 LLM Configuration", id=2):
304295
with gr.Group():
305296
llm_provider = gr.Dropdown(
306-
["anthropic", "openai", "gemini", "azure_openai", "deepseek"],
297+
["anthropic", "openai", "gemini", "azure_openai", "deepseek", ""],
307298
label="LLM Provider",
308299
value="gemini",
309300
info="Select your preferred language model provider"
@@ -391,15 +382,27 @@ def create_ui(theme_name="Citrus"):
391382

392383
with gr.TabItem("🎬 Recordings", id=5):
393384
def list_videos(path):
385+
"""Return the latest video file from the specified path."""
394386
if not os.path.exists(path):
395387
return ["Recording path not found"]
396-
video_files = [f for f in os.listdir(path) if f.endswith(('.mp4', '.webm'))]
397-
return [os.path.join(path, vf) for vf in video_files]
388+
389+
# Get all video files in the directory
390+
video_files = glob.glob(os.path.join(path, '*.[mM][pP]4')) + glob.glob(os.path.join(path, '*.[wW][eE][bB][mM]'))
391+
392+
if not video_files:
393+
return ["No recordings found"]
394+
395+
# Sort files by modification time (latest first)
396+
video_files.sort(key=os.path.getmtime, reverse=True)
397+
398+
# Return only the latest video
399+
return [video_files[0]]
398400

399401
def display_videos(recording_path):
402+
"""Display the latest video in the gallery."""
400403
return list_videos(recording_path)
401404

402-
recording_display = gr.Gallery(label="Recorded Videos", type="video")
405+
recording_display = gr.Gallery(label="Latest Recording", type="video")
403406

404407
demo.load(
405408
display_videos,
@@ -436,17 +439,6 @@ def display_videos(recording_path):
436439
show_label=True
437440
)
438441

439-
# Handle theme changes
440-
def reload_ui(new_theme):
441-
"""Reload the UI with the new theme"""
442-
return create_ui(new_theme)
443-
444-
theme_dropdown.change(
445-
fn=reload_ui,
446-
inputs=[theme_dropdown],
447-
outputs=[demo]
448-
)
449-
450442
# Run button click handler
451443
run_button.click(
452444
fn=run_browser_agent,

0 commit comments

Comments
 (0)