katiue commited on
Commit
1ce41fe
·
verified ·
1 Parent(s): d908334

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. webui.py +79 -64
webui.py CHANGED
@@ -132,9 +132,10 @@ async def run_org_agent(
132
  model_thoughts = history.model_thoughts()
133
 
134
  recorded_files = get_latest_files(save_recording_path)
 
135
 
136
  await browser.close()
137
- return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), recorded_files.get('.zip')
138
  else:
139
  # Reuse existing context
140
  agent = Agent(
@@ -149,7 +150,8 @@ async def run_org_agent(
149
  model_actions = history.model_actions()
150
  model_thoughts = history.model_thoughts()
151
  recorded_files = get_latest_files(save_recording_path)
152
- return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), recorded_files.get('.zip')
 
153
 
154
 
155
  async def run_custom_agent(
@@ -209,7 +211,8 @@ async def run_custom_agent(
209
  model_actions = history.model_actions()
210
  model_thoughts = history.model_thoughts()
211
  recorded_files = get_latest_files(save_recording_path)
212
- return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), recorded_files.get('.zip')
 
213
  else:
214
  browser = CustomBrowser(
215
  config=BrowserConfig(
@@ -301,7 +304,7 @@ async def run_with_stream(*args):
301
  html_content = f"<div class='error'>Screenshot error: {str(e)}</div>"
302
 
303
  yield [html_content, final_result, errors, model_actions, model_thoughts, recording, trace]
304
- await asyncio.sleep(0.2)
305
 
306
  # Get agent results when done
307
  try:
@@ -343,65 +346,77 @@ def main():
343
  # Gradio UI setup
344
  with gr.Blocks(title="Browser Use WebUI", theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Plus Jakarta Sans")])) as demo:
345
  gr.Markdown("<center><h1>Browser Use WebUI</h1></center>")
346
- with gr.Row():
347
- agent_type = gr.Radio(["org", "custom"], label="Agent Type", value="custom")
348
- max_steps = gr.Number(label="max run steps", value=100)
349
- use_vision = gr.Checkbox(label="use vision", value=True)
350
- with gr.Row():
351
- llm_provider = gr.Dropdown(
352
- ["anthropic", "openai", "gemini", "azure_openai", "deepseek"], label="LLM Provider", value="gemini"
353
- )
354
- llm_model_name = gr.Textbox(label="LLM Model Name", value="gemini-2.0-flash-exp")
355
- llm_temperature = gr.Number(label="LLM Temperature", value=1.0)
356
- with gr.Row():
357
- llm_base_url = gr.Textbox(label="LLM Base URL")
358
- llm_api_key = gr.Textbox(label="LLM API Key", type="password")
359
-
360
- with gr.Accordion("Browser Settings", open=False):
361
- use_own_browser = gr.Checkbox(label="Use Own Browser", value=False)
362
- headless = gr.Checkbox(label="Headless", value=False)
363
- disable_security = gr.Checkbox(label="Disable Security", value=True)
364
- with gr.Row():
365
- window_w = gr.Number(label="Window Width", value=1920)
366
- window_h = gr.Number(label="Window Height", value=1080)
367
- save_recording_path = gr.Textbox(label="Save Recording Path", placeholder="e.g. ./tmp/record_videos",
368
- value="./tmp/record_videos")
369
- with gr.Accordion("Task Settings", open=True):
370
- task = gr.Textbox(label="Task", lines=10,
371
- value="go to google.com and type 'OpenAI' click search and give me the first url")
372
- add_infos = gr.Textbox(label="Additional Infos(Optional): Hints to help LLM complete Task", lines=5)
373
-
374
- run_button = gr.Button("Run Agent", variant="primary")
375
- with gr.Column():
376
- # Add live stream viewer before other components
377
- browser_view = gr.HTML(
378
- label="Live Browser View",
379
- value="<div style='width:100%; height:600px; border:1px solid #ccc; display:flex; align-items:center; justify-content:center;'><p>Waiting for browser session...</p></div>"
380
- )
381
- final_result_output = gr.Textbox(label="Final Result", lines=5)
382
- errors_output = gr.Textbox(label="Errors", lines=5)
383
- model_actions_output = gr.Textbox(label="Model Actions", lines=5)
384
- model_thoughts_output = gr.Textbox(label="Model Thoughts", lines=5)
385
- with gr.Row():
386
- recording_file = gr.Video(label="Recording File") # Changed from gr.File to gr.Video
387
- trace_file = gr.File(label="Trace File (ZIP)")
388
-
389
- # Add a refresh button
390
- refresh_button = gr.Button("Refresh Files")
391
 
392
- def refresh_files():
393
- recorded_files = get_latest_files("./tmp/record_videos")
394
- return (
395
- recorded_files.get('.webm') if recorded_files.get('.webm') else None,
396
- recorded_files.get('.zip') if recorded_files.get('.zip') else None
397
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
 
399
- refresh_button.click(
400
- fn=refresh_files,
401
- inputs=[],
402
- outputs=[recording_file, trace_file]
403
- )
404
-
405
  run_button.click(
406
  fn=run_with_stream,
407
  inputs=[
@@ -422,7 +437,7 @@ def main():
422
  max_steps,
423
  use_vision
424
  ],
425
- outputs=[ # Change from dict to list
426
  browser_view,
427
  final_result_output,
428
  errors_output,
@@ -441,8 +456,8 @@ if __name__ == "__main__":
441
  # For local development
442
  import argparse
443
  parser = argparse.ArgumentParser(description="Gradio UI for Browser Agent")
444
- parser.add_argument("--ip", type=str, default="127.0.0.1", help="IP address to bind to")
445
- parser.add_argument("--port", type=int, default=7788, help="Port to listen on")
446
  args = parser.parse_args()
447
  main()
448
  else:
 
132
  model_thoughts = history.model_thoughts()
133
 
134
  recorded_files = get_latest_files(save_recording_path)
135
+ trace_file = get_latest_files(save_recording_path + "/../traces")
136
 
137
  await browser.close()
138
+ return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), trace_file.get('.zip')
139
  else:
140
  # Reuse existing context
141
  agent = Agent(
 
150
  model_actions = history.model_actions()
151
  model_thoughts = history.model_thoughts()
152
  recorded_files = get_latest_files(save_recording_path)
153
+ trace_file = get_latest_files(save_recording_path + "/../traces")
154
+ return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), trace_file.get('.zip')
155
 
156
 
157
  async def run_custom_agent(
 
211
  model_actions = history.model_actions()
212
  model_thoughts = history.model_thoughts()
213
  recorded_files = get_latest_files(save_recording_path)
214
+ trace_file = get_latest_files(save_recording_path + "/../traces")
215
+ return final_result, errors, model_actions, model_thoughts, recorded_files.get('.webm'), trace_file.get('.zip')
216
  else:
217
  browser = CustomBrowser(
218
  config=BrowserConfig(
 
304
  html_content = f"<div class='error'>Screenshot error: {str(e)}</div>"
305
 
306
  yield [html_content, final_result, errors, model_actions, model_thoughts, recording, trace]
307
+ await asyncio.sleep(0.01)
308
 
309
  # Get agent results when done
310
  try:
 
346
  # Gradio UI setup
347
  with gr.Blocks(title="Browser Use WebUI", theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Plus Jakarta Sans")])) as demo:
348
  gr.Markdown("<center><h1>Browser Use WebUI</h1></center>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
 
350
+ with gr.Tabs():
351
+ # Tab for LLM Settings
352
+ with gr.Tab("LLM Settings"):
353
+ with gr.Row():
354
+ llm_provider = gr.Dropdown(
355
+ ["anthropic", "openai", "gemini", "azure_openai", "deepseek"], label="LLM Provider", value="gemini"
356
+ )
357
+ llm_model_name = gr.Textbox(label="LLM Model Name", value="gemini-2.0-flash-exp")
358
+ llm_temperature = gr.Number(label="LLM Temperature", value=1.0)
359
+ with gr.Row():
360
+ llm_base_url = gr.Textbox(label="LLM Base URL")
361
+ llm_api_key = gr.Textbox(label="LLM API Key", type="password")
362
+
363
+ # Tab for Browser Settings
364
+ with gr.Tab("Browser Settings"):
365
+ with gr.Accordion("Browser Settings", open=True):
366
+ use_own_browser = gr.Checkbox(label="Use Own Browser", value=False)
367
+ headless = gr.Checkbox(label="Headless", value=False)
368
+ disable_security = gr.Checkbox(label="Disable Security", value=True)
369
+ with gr.Row():
370
+ window_w = gr.Number(label="Window Width", value=1920)
371
+ window_h = gr.Number(label="Window Height", value=1080)
372
+ save_recording_path = gr.Textbox(label="Save Recording Path", placeholder="e.g. ./tmp/record_videos",
373
+ value="./tmp/record_videos")
374
+
375
+ # Tab for Task Settings
376
+ with gr.Tab("Task Settings"):
377
+ with gr.Accordion("Task Settings", open=True):
378
+ task = gr.Textbox(label="Task", lines=10,
379
+ value="go to google.com and type 'OpenAI' click search and give me the first url")
380
+ add_infos = gr.Textbox(label="Additional Infos (Optional): Hints to help LLM complete Task", lines=5)
381
+ agent_type = gr.Radio(["org", "custom"], label="Agent Type", value="custom")
382
+ max_steps = gr.Number(label="Max Run Steps", value=100)
383
+ use_vision = gr.Checkbox(label="Use Vision", value=True)
384
+
385
+ # Tab for Stream + File Download and Agent Thoughts
386
+ with gr.Tab("Results"):
387
+ with gr.Column():
388
+ # Add live stream viewer before other components
389
+ browser_view = gr.HTML(
390
+ label="Live Browser View",
391
+ value="<div style='width:100%; height:600px; border:1px solid #ccc; display:flex; align-items:center; justify-content:center;'><p>Waiting for browser session...</p></div>"
392
+ )
393
+ final_result_output = gr.Textbox(label="Final Result", lines=5)
394
+ errors_output = gr.Textbox(label="Errors", lines=5)
395
+ model_actions_output = gr.Textbox(label="Model Actions", lines=5)
396
+ model_thoughts_output = gr.Textbox(label="Model Thoughts", lines=5)
397
+ with gr.Row():
398
+ recording_file = gr.Video(label="Recording File") # Changed from gr.File to gr.Video
399
+ trace_file = gr.File(label="Trace File (ZIP)")
400
+
401
+ # Add a refresh button
402
+ refresh_button = gr.Button("Refresh Files")
403
+
404
+ def refresh_files():
405
+ recorded_files = get_latest_files("./tmp/record_videos")
406
+ trace_file = get_latest_files("./tmp/traces")
407
+ return (
408
+ recorded_files.get('.webm') if recorded_files.get('.webm') else None,
409
+ trace_file.get('.zip') if trace_file.get('.zip') else None
410
+ )
411
+
412
+ refresh_button.click(
413
+ fn=refresh_files,
414
+ inputs=[],
415
+ outputs=[recording_file, trace_file]
416
+ )
417
 
418
+ # Run button outside tabs for global execution
419
+ run_button = gr.Button("Run Agent", variant="primary")
 
 
 
 
420
  run_button.click(
421
  fn=run_with_stream,
422
  inputs=[
 
437
  max_steps,
438
  use_vision
439
  ],
440
+ outputs=[
441
  browser_view,
442
  final_result_output,
443
  errors_output,
 
456
  # For local development
457
  import argparse
458
  parser = argparse.ArgumentParser(description="Gradio UI for Browser Agent")
459
+ parser.add_argument("--ip", type=str, default="0.0.0.0", help="IP address to bind to")
460
+ parser.add_argument("--port", type=int, default=7860, help="Port to listen on")
461
  args = parser.parse_args()
462
  main()
463
  else: