Skip to content

Commit 2654e6b

Browse files
authored
Merge pull request #117 from vvincent1234/fix/win_font_error
hotfix font error and stream error
2 parents 453dd43 + 7bbf2d6 commit 2654e6b

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
browser-use==0.1.18
1+
browser-use==0.1.19
22
langchain-google-genai==2.0.8
33
pyperclip==1.9.0
44
gradio==5.9.1

webui.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def run_browser_agent(
189189
trace_file,
190190
history_file,
191191
gr.update(value="Stop", interactive=True), # Re-enable stop button
192-
gr.update(value="Run", interactive=True) # Re-enable run button
192+
gr.update(interactive=True) # Re-enable run button
193193
)
194194

195195
except Exception as e:
@@ -205,7 +205,7 @@ async def run_browser_agent(
205205
None, # history_file
206206
None, # trace_file
207207
gr.update(value="Stop", interactive=True), # Re-enable stop button
208-
gr.update(value="Run", interactive=True) # Re-enable run button
208+
gr.update(interactive=True) # Re-enable run button
209209
)
210210

211211

@@ -422,6 +422,7 @@ async def run_with_stream(
422422
max_actions_per_step,
423423
tool_call_in_content
424424
):
425+
global _global_agent_state
425426
stream_vw = 80
426427
stream_vh = int(80 * window_h // window_w)
427428
if not headless:
@@ -454,6 +455,7 @@ async def run_with_stream(
454455
yield [html_content] + list(result)
455456
else:
456457
try:
458+
_global_agent_state.clear_stop()
457459
# Run the browser agent in the background
458460
agent_task = asyncio.create_task(
459461
run_browser_agent(
@@ -485,7 +487,7 @@ async def run_with_stream(
485487
# Initialize values for streaming
486488
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Using browser...</h1>"
487489
final_result = errors = model_actions = model_thoughts = ""
488-
latest_videos = trace = None
490+
latest_videos = trace = history_file = None
489491

490492

491493
# Periodically update the stream while the agent task is running
@@ -498,27 +500,40 @@ async def run_with_stream(
498500
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Waiting for browser session...</h1>"
499501
except Exception as e:
500502
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Waiting for browser session...</h1>"
501-
502-
yield [
503-
html_content,
504-
final_result,
505-
errors,
506-
model_actions,
507-
model_thoughts,
508-
latest_videos,
509-
trace,
510-
gr.update(value="Stop", interactive=True), # Re-enable stop button
511-
gr.update(value="Run", interactive=True) # Re-enable run button
512-
]
503+
504+
if _global_agent_state and _global_agent_state.is_stop_requested():
505+
yield [
506+
html_content,
507+
final_result,
508+
errors,
509+
model_actions,
510+
model_thoughts,
511+
latest_videos,
512+
trace,
513+
history_file,
514+
gr.update(value="Stopping...", interactive=False), # stop_button
515+
gr.update(interactive=False), # run_button
516+
]
517+
break
518+
else:
519+
yield [
520+
html_content,
521+
final_result,
522+
errors,
523+
model_actions,
524+
model_thoughts,
525+
latest_videos,
526+
trace,
527+
history_file,
528+
gr.update(value="Stop", interactive=True), # Re-enable stop button
529+
gr.update(interactive=True) # Re-enable run button
530+
]
513531
await asyncio.sleep(0.05)
514532

515533
# Once the agent task completes, get the results
516534
try:
517535
result = await agent_task
518-
if isinstance(result, tuple) and len(result) == 8:
519-
final_result, errors, model_actions, model_thoughts, latest_videos, trace, stop_button, run_button = result
520-
else:
521-
errors = "Unexpected result format from agent"
536+
final_result, errors, model_actions, model_thoughts, latest_videos, trace, history_file, stop_button, run_button = result
522537
except Exception as e:
523538
errors = f"Agent error: {str(e)}"
524539

@@ -530,6 +545,7 @@ async def run_with_stream(
530545
model_thoughts,
531546
latest_videos,
532547
trace,
548+
history_file,
533549
stop_button,
534550
run_button
535551
]
@@ -544,8 +560,9 @@ async def run_with_stream(
544560
"",
545561
None,
546562
None,
563+
None,
547564
gr.update(value="Stop", interactive=True), # Re-enable stop button
548-
gr.update(value="Run", interactive=True) # Re-enable run button
565+
gr.update(interactive=True) # Re-enable run button
549566
]
550567

551568
# Define the theme map globally

0 commit comments

Comments
 (0)