Spaces:
Sleeping
Sleeping
Update app.py
Browse filesyet another try
app.py
CHANGED
|
@@ -72,29 +72,27 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 72 |
# print("Screenshot saved!")
|
| 73 |
|
| 74 |
async def capture_screenshot():
|
| 75 |
-
"""Launches Playwright and captures a screenshot of
|
| 76 |
print("Launching Playwright...")
|
| 77 |
async with async_playwright() as p:
|
| 78 |
browser = await p.chromium.launch(headless=True)
|
| 79 |
page = await browser.new_page()
|
| 80 |
-
|
| 81 |
-
print("Opening the p5.js sketch...")
|
| 82 |
-
#https://raw.githubusercontent.com/your-username/repository-name/branch-name/path/to/image.png
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
print("
|
| 87 |
-
await page.
|
| 88 |
|
| 89 |
-
print("Waiting for
|
| 90 |
-
await page.wait_for_selector("
|
| 91 |
|
| 92 |
print("Capturing screenshot...")
|
| 93 |
await page.screenshot(path="img.png")
|
| 94 |
await browser.close()
|
| 95 |
print("Screenshot saved!")
|
| 96 |
-
|
| 97 |
-
|
| 98 |
@tool
|
| 99 |
def grab_image() -> Image:
|
| 100 |
"""
|
|
|
|
| 72 |
# print("Screenshot saved!")
|
| 73 |
|
| 74 |
async def capture_screenshot():
|
| 75 |
+
"""Launches Playwright and captures a screenshot of an image from GitHub."""
|
| 76 |
print("Launching Playwright...")
|
| 77 |
async with async_playwright() as p:
|
| 78 |
browser = await p.chromium.launch(headless=True)
|
| 79 |
page = await browser.new_page()
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
# Use the raw GitHub image URL
|
| 82 |
+
#https://github.com/kfahn22/Op-Art/blob/main/assets/gears.jpg
|
| 83 |
+
image_url = "https://raw.githubusercontent.com/kfahn22/repository-name/Op-Art/main/assets/gears.jpg"
|
| 84 |
|
| 85 |
+
print(f"Opening image from GitHub: {image_url}")
|
| 86 |
+
await page.goto(image_url, timeout=120000) # Wait for the image page to load
|
| 87 |
|
| 88 |
+
print("Waiting for image element...")
|
| 89 |
+
await page.wait_for_selector("img", timeout=120000) # Wait for the <img> to be visible
|
| 90 |
|
| 91 |
print("Capturing screenshot...")
|
| 92 |
await page.screenshot(path="img.png")
|
| 93 |
await browser.close()
|
| 94 |
print("Screenshot saved!")
|
| 95 |
+
|
|
|
|
| 96 |
@tool
|
| 97 |
def grab_image() -> Image:
|
| 98 |
"""
|