Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -44,22 +44,44 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
44 |
|
45 |
|
46 |
# Debugging: Print statements to track execution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
async def capture_screenshot():
|
|
|
48 |
print("Launching Playwright...")
|
49 |
async with async_playwright() as p:
|
50 |
-
browser = await p.chromium.launch(headless=True)
|
51 |
page = await browser.new_page()
|
|
|
52 |
print("Opening the p5.js sketch...")
|
53 |
-
await page.goto("https://editor.p5js.org/kfahn/full/2XD5Y8MiV", timeout=
|
|
|
|
|
|
|
54 |
|
55 |
print("Waiting for canvas element...")
|
56 |
-
await page.wait_for_selector("canvas") #
|
57 |
-
await page.wait_for_timeout(5000) # Additional wait
|
58 |
|
59 |
print("Capturing screenshot...")
|
60 |
await page.screenshot(path="img.png")
|
61 |
await browser.close()
|
62 |
print("Screenshot saved!")
|
|
|
63 |
|
64 |
@tool
|
65 |
def grab_image() -> Image:
|
|
|
44 |
|
45 |
|
46 |
# Debugging: Print statements to track execution
|
47 |
+
# async def capture_screenshot():
|
48 |
+
# print("Launching Playwright...")
|
49 |
+
# async with async_playwright() as p:
|
50 |
+
# browser = await p.chromium.launch(headless=True)
|
51 |
+
# page = await browser.new_page()
|
52 |
+
# print("Opening the p5.js sketch...")
|
53 |
+
# await page.goto("https://editor.p5js.org/kfahn/full/2XD5Y8MiV", timeout=6000)
|
54 |
+
|
55 |
+
# print("Waiting for canvas element...")
|
56 |
+
# await page.wait_for_selector("canvas") # Ensure p5.js has loaded
|
57 |
+
# await page.wait_for_timeout(5000) # Additional wait
|
58 |
+
|
59 |
+
# print("Capturing screenshot...")
|
60 |
+
# await page.screenshot(path="img.png")
|
61 |
+
# await browser.close()
|
62 |
+
# print("Screenshot saved!")
|
63 |
+
|
64 |
async def capture_screenshot():
|
65 |
+
"""Launches Playwright and captures a screenshot of a p5.js sketch."""
|
66 |
print("Launching Playwright...")
|
67 |
async with async_playwright() as p:
|
68 |
+
browser = await p.chromium.launch(headless=True)
|
69 |
page = await browser.new_page()
|
70 |
+
|
71 |
print("Opening the p5.js sketch...")
|
72 |
+
await page.goto("https://editor.p5js.org/kfahn/full/2XD5Y8MiV", timeout=60000) # Increased timeout
|
73 |
+
|
74 |
+
print("Waiting for page to load fully...")
|
75 |
+
await page.wait_for_load_state("networkidle") # Ensures all requests finish
|
76 |
|
77 |
print("Waiting for canvas element...")
|
78 |
+
await page.wait_for_selector("canvas", timeout=60000) # Increased timeout
|
|
|
79 |
|
80 |
print("Capturing screenshot...")
|
81 |
await page.screenshot(path="img.png")
|
82 |
await browser.close()
|
83 |
print("Screenshot saved!")
|
84 |
+
|
85 |
|
86 |
@tool
|
87 |
def grab_image() -> Image:
|