Spaces:
Sleeping
Sleeping
Update app.py
Browse filesStart adding logic for image choice
app.py
CHANGED
@@ -23,16 +23,6 @@ subprocess.run(["apt-get", "install", "-y", "libnss3", "libatk1.0-0", "libatk-br
|
|
23 |
|
24 |
subprocess.run(["playwright", "install", "chromium"])
|
25 |
|
26 |
-
# def install_playwright_and_deps():
|
27 |
-
# try:
|
28 |
-
# # Install Playwright
|
29 |
-
# subprocess.check_call(["pip", "install", "playwright"])
|
30 |
-
# subprocess.check_call(["apt-get", "playwright", "install-deps"])
|
31 |
-
# except subprocess.CalledProcessError as e:
|
32 |
-
# print(f"Error installing Playwright or dependencies: {e}")
|
33 |
-
|
34 |
-
# install_playwright_and_deps()
|
35 |
-
|
36 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
37 |
@tool
|
38 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
@@ -44,32 +34,16 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
44 |
"""
|
45 |
return "What magic will you build ?"
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
# async def capture_screenshot():
|
58 |
-
# print("Launching Playwright...")
|
59 |
-
# async with async_playwright() as p:
|
60 |
-
# browser = await p.chromium.launch(headless=True)
|
61 |
-
# page = await browser.new_page()
|
62 |
-
# print("Opening the p5.js sketch...")
|
63 |
-
# await page.goto("https://editor.p5js.org/kfahn/full/2XD5Y8MiV", timeout=6000)
|
64 |
-
|
65 |
-
# print("Waiting for canvas element...")
|
66 |
-
# await page.wait_for_selector("canvas") # Ensure p5.js has loaded
|
67 |
-
# await page.wait_for_timeout(5000) # Additional wait
|
68 |
-
|
69 |
-
# print("Capturing screenshot...")
|
70 |
-
# await page.screenshot(path="img.png")
|
71 |
-
# await browser.close()
|
72 |
-
# print("Screenshot saved!")
|
73 |
|
74 |
async def capture_screenshot():
|
75 |
"""Launches Playwright and captures a screenshot of an image from p5.js."""
|
@@ -93,7 +67,7 @@ async def capture_screenshot():
|
|
93 |
await browser.close()
|
94 |
print("Screenshot saved!")
|
95 |
|
96 |
-
|
97 |
def grab_image() -> Image:
|
98 |
"""
|
99 |
Fetches an op art image from a p5.js sketch.
|
@@ -112,7 +86,7 @@ def grab_image() -> Image:
|
|
112 |
return img
|
113 |
|
114 |
|
115 |
-
|
116 |
@tool
|
117 |
def get_joke() -> str:
|
118 |
"""
|
@@ -141,7 +115,7 @@ def get_joke() -> str:
|
|
141 |
except requests.exceptions.RequestException as e:
|
142 |
return f"Error fetching joke: {str(e)}"
|
143 |
|
144 |
-
|
145 |
@tool
|
146 |
def get_current_time_in_timezone(timezone: str) -> str:
|
147 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
23 |
|
24 |
subprocess.run(["playwright", "install", "chromium"])
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
27 |
@tool
|
28 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
34 |
"""
|
35 |
return "What magic will you build ?"
|
36 |
|
37 |
+
|
38 |
+
def chooseImage(type: str)-> str:
|
39 |
+
"""Returns a url based on a person's reuqested type of image.
|
40 |
+
Args:
|
41 |
+
type: the type of image the person would like to see
|
42 |
+
Returns:
|
43 |
+
str: a url
|
44 |
+
"""
|
45 |
+
|
46 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
async def capture_screenshot():
|
49 |
"""Launches Playwright and captures a screenshot of an image from p5.js."""
|
|
|
67 |
await browser.close()
|
68 |
print("Screenshot saved!")
|
69 |
|
70 |
+
|
71 |
def grab_image() -> Image:
|
72 |
"""
|
73 |
Fetches an op art image from a p5.js sketch.
|
|
|
86 |
return img
|
87 |
|
88 |
|
89 |
+
|
90 |
@tool
|
91 |
def get_joke() -> str:
|
92 |
"""
|
|
|
115 |
except requests.exceptions.RequestException as e:
|
116 |
return f"Error fetching joke: {str(e)}"
|
117 |
|
118 |
+
#https://github.com/huggingface/smolagents/blob/main/examples/multiple_tools.py
|
119 |
@tool
|
120 |
def get_current_time_in_timezone(timezone: str) -> str:
|
121 |
"""A tool that fetches the current local time in a specified timezone.
|