Spaces:
Sleeping
Sleeping
Update app.py
Browse filesstart adding more options
app.py
CHANGED
@@ -8,6 +8,7 @@ import nest_asyncio
|
|
8 |
from playwright.async_api import async_playwright
|
9 |
from PIL import Image
|
10 |
import subprocess
|
|
|
11 |
import gradio as gr
|
12 |
|
13 |
from tools.final_answer import FinalAnswerTool
|
@@ -35,18 +36,17 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
35 |
return "What magic will you build ?"
|
36 |
|
37 |
|
38 |
-
def
|
39 |
-
"""
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
str: a url
|
44 |
-
"""
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
print("Launching Playwright...")
|
51 |
async with async_playwright() as p:
|
52 |
browser = await p.chromium.launch(headless=True)
|
@@ -54,7 +54,13 @@ async def capture_screenshot():
|
|
54 |
|
55 |
#url = "https://openprocessing.org/sketch/2539973"
|
56 |
url = "https://editor.p5js.org/kfahn/full/2XD5Y8MiV"
|
57 |
-
image_url
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
print(f"Opening image from p5 sketch: {image_url}")
|
60 |
await page.goto(image_url, timeout=120000) # Wait for the image page to load
|
|
|
8 |
from playwright.async_api import async_playwright
|
9 |
from PIL import Image
|
10 |
import subprocess
|
11 |
+
import json
|
12 |
import gradio as gr
|
13 |
|
14 |
from tools.final_answer import FinalAnswerTool
|
|
|
36 |
return "What magic will you build ?"
|
37 |
|
38 |
|
39 |
+
def load_image_sources():
|
40 |
+
with open("image_sources.json", "r") as file:
|
41 |
+
return json.load(file)
|
42 |
+
|
43 |
+
image_sources = load_image_sources()
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
def get_image_url(image_type: str):
|
46 |
+
return image_sources.get(image_type, None)
|
47 |
+
|
48 |
+
async def capture_screenshot(image_type: str):
|
49 |
+
"""Launches Playwright and uses user input, if any, to captures a screenshot of an image from p5.js."""
|
50 |
print("Launching Playwright...")
|
51 |
async with async_playwright() as p:
|
52 |
browser = await p.chromium.launch(headless=True)
|
|
|
54 |
|
55 |
#url = "https://openprocessing.org/sketch/2539973"
|
56 |
url = "https://editor.p5js.org/kfahn/full/2XD5Y8MiV"
|
57 |
+
image_url
|
58 |
+
if (image_type):
|
59 |
+
image_url = get_image_url()
|
60 |
+
elif:
|
61 |
+
image_url = url
|
62 |
+
else:
|
63 |
+
Return: f"Unable to fetch image"
|
64 |
|
65 |
print(f"Opening image from p5 sketch: {image_url}")
|
66 |
await page.goto(image_url, timeout=120000) # Wait for the image page to load
|