Skip to content

Commit

Permalink
Merge pull request #117 from vvincent1234/fix/win_font_error
Browse files Browse the repository at this point in the history
hotfix font error and stream error
  • Loading branch information
warmshao authored Jan 16, 2025
2 parents 453dd43 + 7bbf2d6 commit 2654e6b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
browser-use==0.1.18
browser-use==0.1.19
langchain-google-genai==2.0.8
pyperclip==1.9.0
gradio==5.9.1
Expand Down
57 changes: 37 additions & 20 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def run_browser_agent(
trace_file,
history_file,
gr.update(value="Stop", interactive=True), # Re-enable stop button
gr.update(value="Run", interactive=True) # Re-enable run button
gr.update(interactive=True) # Re-enable run button
)

except Exception as e:
Expand All @@ -205,7 +205,7 @@ async def run_browser_agent(
None, # history_file
None, # trace_file
gr.update(value="Stop", interactive=True), # Re-enable stop button
gr.update(value="Run", interactive=True) # Re-enable run button
gr.update(interactive=True) # Re-enable run button
)


Expand Down Expand Up @@ -422,6 +422,7 @@ async def run_with_stream(
max_actions_per_step,
tool_call_in_content
):
global _global_agent_state
stream_vw = 80
stream_vh = int(80 * window_h // window_w)
if not headless:
Expand Down Expand Up @@ -454,6 +455,7 @@ async def run_with_stream(
yield [html_content] + list(result)
else:
try:
_global_agent_state.clear_stop()
# Run the browser agent in the background
agent_task = asyncio.create_task(
run_browser_agent(
Expand Down Expand Up @@ -485,7 +487,7 @@ async def run_with_stream(
# Initialize values for streaming
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Using browser...</h1>"
final_result = errors = model_actions = model_thoughts = ""
latest_videos = trace = None
latest_videos = trace = history_file = None


# Periodically update the stream while the agent task is running
Expand All @@ -498,27 +500,40 @@ async def run_with_stream(
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Waiting for browser session...</h1>"
except Exception as e:
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Waiting for browser session...</h1>"

yield [
html_content,
final_result,
errors,
model_actions,
model_thoughts,
latest_videos,
trace,
gr.update(value="Stop", interactive=True), # Re-enable stop button
gr.update(value="Run", interactive=True) # Re-enable run button
]

if _global_agent_state and _global_agent_state.is_stop_requested():
yield [
html_content,
final_result,
errors,
model_actions,
model_thoughts,
latest_videos,
trace,
history_file,
gr.update(value="Stopping...", interactive=False), # stop_button
gr.update(interactive=False), # run_button
]
break
else:
yield [
html_content,
final_result,
errors,
model_actions,
model_thoughts,
latest_videos,
trace,
history_file,
gr.update(value="Stop", interactive=True), # Re-enable stop button
gr.update(interactive=True) # Re-enable run button
]
await asyncio.sleep(0.05)

# Once the agent task completes, get the results
try:
result = await agent_task
if isinstance(result, tuple) and len(result) == 8:
final_result, errors, model_actions, model_thoughts, latest_videos, trace, stop_button, run_button = result
else:
errors = "Unexpected result format from agent"
final_result, errors, model_actions, model_thoughts, latest_videos, trace, history_file, stop_button, run_button = result
except Exception as e:
errors = f"Agent error: {str(e)}"

Expand All @@ -530,6 +545,7 @@ async def run_with_stream(
model_thoughts,
latest_videos,
trace,
history_file,
stop_button,
run_button
]
Expand All @@ -544,8 +560,9 @@ async def run_with_stream(
"",
None,
None,
None,
gr.update(value="Stop", interactive=True), # Re-enable stop button
gr.update(value="Run", interactive=True) # Re-enable run button
gr.update(interactive=True) # Re-enable run button
]

# Define the theme map globally
Expand Down

1 comment on commit 2654e6b

@Gyoonus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still error occured about font

browser-use-webui-1 | 2025-01-16 02:36:09,784 DEBG 'webui' stderr output:
browser-use-webui-1 | File "/app/src/agent/custom_agent.py", line 307, in create_history_gif
browser-use-webui-1 | task_frame = self._create_task_frame(
browser-use-webui-1 | ^^^^^^^^^^^^^^^^^^^^^^^^
browser-use-webui-1 | File "/usr/local/lib/python3.11/site-packages/browser_use/agent/service.py", line 713, in _create_task_frame
browser-use-webui-1 | larger_font = ImageFont.truetype(
browser-use-webui-1 | ^^^^^^^^^^^^^^^^^^^
browser-use-webui-1 | File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 879, in truetype
browser-use-webui-1 | return freetype(font)
browser-use-webui-1 | ^^^^^^^^^^^^^^
browser-use-webui-1 | File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 876, in freetype
browser-use-webui-1 | return FreeTypeFont(font, size, index, encoding, layout_engine)
browser-use-webui-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
browser-use-webui-1 | File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 288, in init
browser-use-webui-1 | load_from_bytes(cast(IO[bytes], font))
browser-use-webui-1 | File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 268, in load_from_bytes
browser-use-webui-1 | self.font = core.getfont(
browser-use-webui-1 | ^^^^^^^^^^^^^
browser-use-webui-1 | OSError: cannot open resource

Please sign in to comment.