Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

revert gradio demo

wwwc7c17701de311
diff --git a/examples/ui/gradio_demo.py b/examples/ui/gradio_demo.py
index 765a60412..e34609466 100644
--- a/examples/ui/gradio_demo.py
+++ b/examples/ui/gradio_demo.py
@@ -1,12 +1,3 @@
-"""
-This script creates a Gradio interface to run browser tasks using OpenAI models.
-By default, it uses regular OpenAI. To use Azure OpenAI, set the AZURE_ENDPOINT environment variable:
-
-- AZURE_ENDPOINT: Your Azure OpenAI endpoint URL
-
-The script will automatically detect this variable and switch to using Azure OpenAI if it is set.
-"""
-
import asyncio
import os
from dataclasses import dataclass
@@ -21,14 +12,6 @@ from rich.text import Text
from browser_use import Agent
-# Conditionally import AzureChatOpenAI or ChatOpenAI based on the presence of the AZURE_ENDPOINT environment variable
-if os.getenv("AZURE_ENDPOINT"):
- from langchain_openai import AzureChatOpenAI as ChatOpenAI # Use Azure if environment variable is set
-else:
- from langchain_openai import ChatOpenAI # Use regular OpenAI otherwise
-
-from browser_use import Agent
-
load_dotenv()
@@ -66,48 +49,26 @@ def parse_agent_history(history_str: str) -> None:
async def run_browser_task(
- task: str,
- api_key: str,
- model: str = 'gpt-4',
- headless: bool = True,
+ task: str,
+ api_key: str,
+ model: str = 'gpt-4o',
+ headless: bool = True,
) -> str:
- if not api_key.strip():
- return 'Please provide an API key'
-
- azure_endpoint = os.getenv("AZURE_ENDPOINT")
-
- if azure_endpoint:
- os.environ['AZURE_API_KEY'] = api_key
- os.environ['AZURE_ENDPOINT'] = azure_endpoint
- os.environ['OPENAI_API_VERSION'] = '2024-08-01-preview' # Set the API version globally for Azure OpenAI
-
- try:
- agent = Agent(
- task=task,
- llm=ChatOpenAI(
- model_name=model,
- openai_api_key=api_key,
- azure_endpoint=azure_endpoint,
- deployment_name=model,
- api_version='2024-08-01-preview' # Explicitly set the API version
- ),
- )
- except Exception as e:
- return f'Error: {str(e)}'
- else:
- os.environ['OPENAI_API_KEY'] = api_key
-
- try:
- agent = Agent(
- task=task,
- llm=ChatOpenAI(model=model),
- )
- except Exception as e:
- return f'Error: {str(e)}'
-
- result = await agent.run()
- return result
-
+ if not api_key.strip():
+ return 'Please provide an API key'
+
+ os.environ['OPENAI_API_KEY'] = api_key
+
+ try:
+ agent = Agent(
+ task=task,
+ llm=ChatOpenAI(model='gpt-4o'),
+ )
+ result = await agent.run()
+ # TODO: The result cloud be parsed better
+ return result
+ except Exception as e:
+ return f'Error: {str(e)}'
def create_ui():
@@ -123,7 +84,7 @@ def create_ui():
lines=3,
)
model = gr.Dropdown(
- choices=['gpt-4o', 'gpt-4', 'gpt-3.5-turbo'], # Added gpt-4o
+ choices=['gpt-4', 'gpt-3.5-turbo'], label='Model', value='gpt-4'
)
headless = gr.Checkbox(label='Run Headless', value=True)
submit_btn = gr.Button('Run Task')
@@ -142,4 +103,4 @@ def create_ui():
if __name__ == '__main__':
demo = create_ui()
- demo.launch()
+ demo.launch()
\ No newline at end of file