# import os # import subprocess # # Install BrowserGym dependencies before running the main application # def install_browsergym(): # try: # print("Installing BrowserGym dependencies...") # subprocess.run("cd BrowserGym && make install", shell=True, check=True) # print("BrowserGym installation completed successfully") # except subprocess.CalledProcessError as e: # print(f"Error installing BrowserGym: {e}") # raise # install_browsergym() import os import logging import gradio as gr import openai import multiprocessing from process_run import process_run # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[ logging.StreamHandler(), ] ) logger = logging.getLogger(__name__) logger.setLevel('INFO') # Set your OpenAI API key openai.api_key = os.getenv("OPENAI_API_KEY") # Example instructions to display EXAMPLES = [ "When did the solar system form? Find on wikipedia.", "Find the rating of Monopoly (1935) on boardgamegeek.com", ] URL_EXAMPLES = [ "about:blank", "https://www.wikipedia.org", "https://www.boardgamegeek.com" ] def main(): logger.info("Starting BrowserGym web agent") with gr.Blocks(title="WebShephered Demo") as demo: # Add CSS for outlined groups gr.Markdown("# WebShephered Demo") with gr.Row(): with gr.Column(scale=2): with gr.Column(): instruction = gr.Textbox( label="Instruction", placeholder="Enter your instruction here", lines=2, ) gr.Examples( examples=[[e] for e in EXAMPLES], inputs=instruction, cache_examples=False, ) gr.Markdown("\n\n") with gr.Column(): start_url = gr.Textbox( label="Starting URL", placeholder="URL to start the browser at", value="about:blank" ) gr.Examples( examples=URL_EXAMPLES, inputs=start_url, cache_examples=False, ) gr.Markdown("\n\n") model_name = gr.Dropdown( label="Agent Model", choices=["gpt-4o"], value="gpt-4o" ) run_btn = gr.Button("Run Demo") gr.Markdown("---") with gr.Column(): gr.Markdown("## Current State") state_view = gr.Markdown() browser_view = gr.Image(label="Browser View") gr.Markdown("### Task Checklist from WebShephered") checklist_view = gr.Markdown() gr.Markdown("### Action Selection in current step") with gr.Row() as rm_row: rm_cards_container = gr.HTML() with gr.Column(scale=2): gr.Markdown("## Trajectory") trajectory_container = gr.HTML() # Placeholder for our custom trajectory component run_btn.click( fn=process_run, inputs=[instruction, model_name, start_url], outputs=[state_view, browser_view, checklist_view, rm_cards_container, trajectory_container], api_name="run_agent", concurrency_limit=32, show_progress=True ) logger.info("Launching Gradio interface") # Set max_threads to allow multiple concurrent requests demo.launch(share=True, max_threads=32) if __name__ == "__main__": # Add support for multiprocessing on Windows multiprocessing.freeze_support() main()