Spaces:
Sleeping
Sleeping
File size: 3,641 Bytes
be72cce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import os
import subprocess
import sys
# Now import the rest of the modules
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()
|