FreeAIModelsForSure commited on
Commit
4f74b04
·
verified ·
1 Parent(s): bfabb90

Create agent.py

Browse files
Files changed (1) hide show
  1. agent.py +29 -0
agent.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from playwright.async_api import async_playwright
3
+ import json
4
+ from vision_engine import get_elements_from_screenshot
5
+ from browser_engine import take_screenshot, click_element
6
+
7
+ async def main():
8
+ async with async_playwright() as p:
9
+ browser = await p.chromium.launch(headless=True)
10
+ page = await browser.new_page()
11
+ await page.goto("https://www.google.com") # Replace with ur target
12
+
13
+ # 1. Take a look
14
+ img_path = await take_screenshot(page)
15
+
16
+ # 2. Ask Vision model where things are
17
+ json_response = get_elements_from_screenshot(img_path)
18
+ elements = json.loads(json_response)
19
+
20
+ # 3. Decision Logic (Hardcoded for testing)
21
+ target = next((e for e in elements if e["name"] == "search_magnifying_glass"), None)
22
+ if target:
23
+ x = (target["box"][0] + target["box"][2]) / 2
24
+ y = (target["box"][1] + target["box"][3]) / 2
25
+ await click_element(page, x, y)
26
+
27
+ await browser.close()
28
+
29
+ asyncio.run(main())