@@ -408,6 +408,8 @@ async def run_with_stream(
408
408
max_actions_per_step ,
409
409
tool_call_in_content
410
410
):
411
+ stream_vw = 80
412
+ stream_vh = int (80 * window_h // window_w )
411
413
if not headless :
412
414
result = await run_browser_agent (
413
415
agent_type = agent_type ,
@@ -433,7 +435,7 @@ async def run_with_stream(
433
435
tool_call_in_content = tool_call_in_content
434
436
)
435
437
# Add HTML content at the start of the result array
436
- html_content = "<h1 style='width:80vw ; height:90vh '>Using browser...</h1>"
438
+ html_content = f "<h1 style='width:{ stream_vw } vw ; height:{ stream_vh } vh '>Using browser...</h1>"
437
439
yield [html_content ] + list (result )
438
440
else :
439
441
try :
@@ -465,17 +467,21 @@ async def run_with_stream(
465
467
)
466
468
467
469
# Initialize values for streaming
468
- html_content = "<h1 style='width:80vw ; height:90vh '>Using browser...</h1>"
470
+ html_content = f "<h1 style='width:{ stream_vw } vw ; height:{ stream_vh } vh '>Using browser...</h1>"
469
471
final_result = errors = model_actions = model_thoughts = ""
470
472
latest_videos = trace = None
471
473
472
474
473
475
# Periodically update the stream while the agent task is running
474
476
while not agent_task .done ():
475
477
try :
476
- html_content = await capture_screenshot (_global_browser_context )
478
+ encoded_screenshot = await capture_screenshot (_global_browser_context )
479
+ if encoded_screenshot is not None :
480
+ html_content = f'<img src="data:image/jpeg;base64,{ encoded_screenshot } " style="width:{ stream_vw } vw; height:{ stream_vh } vh ; border:1px solid #ccc;">'
481
+ else :
482
+ html_content = f"<h1 style='width:{ stream_vw } vw; height:{ stream_vh } vh'>Waiting for browser session...</h1>"
477
483
except Exception as e :
478
- html_content = f"<h1 style='width:80vw ; height:90vh '>Waiting for browser session...</h1>"
484
+ html_content = f"<h1 style='width:{ stream_vw } vw ; height:{ stream_vh } vh '>Waiting for browser session...</h1>"
479
485
480
486
yield [
481
487
html_content ,
@@ -488,7 +494,7 @@ async def run_with_stream(
488
494
gr .update (value = "Stop" , interactive = True ), # Re-enable stop button
489
495
gr .update (value = "Run" , interactive = True ) # Re-enable run button
490
496
]
491
- await asyncio .sleep (0.01 )
497
+ await asyncio .sleep (0.05 )
492
498
493
499
# Once the agent task completes, get the results
494
500
try :
@@ -515,7 +521,7 @@ async def run_with_stream(
515
521
except Exception as e :
516
522
import traceback
517
523
yield [
518
- f"<h1 style='width:80vw ; height:90vh '>Waiting for browser session...</h1>" ,
524
+ f"<h1 style='width:{ stream_vw } vw ; height:{ stream_vh } vh '>Waiting for browser session...</h1>" ,
519
525
"" ,
520
526
f"Error: { str (e )} \n { traceback .format_exc ()} " ,
521
527
"" ,
@@ -740,7 +746,7 @@ def create_ui(theme_name="Ocean"):
740
746
741
747
with gr .Row ():
742
748
browser_view = gr .HTML (
743
- value = "<h1 style='width:80vw; height:90vh '>Waiting for browser session...</h1>" ,
749
+ value = "<h1 style='width:80vw; height:50vh '>Waiting for browser session...</h1>" ,
744
750
label = "Live Browser View" ,
745
751
)
746
752
0 commit comments