Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,37 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
-
|
8 |
-
from Gradio_UI import GradioUI
|
9 |
-
|
10 |
-
import playwright.sync_api as playwright
|
11 |
|
12 |
@tool
|
13 |
-
def
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
"""
|
20 |
-
|
21 |
-
browser = p.chromium.launch(headless=True)
|
22 |
-
page = browser.new_page()
|
23 |
-
|
24 |
-
script = """
|
25 |
-
() => JSON.stringify({
|
26 |
-
userAgent: navigator.userAgent,
|
27 |
-
platform: navigator.platform,
|
28 |
-
language: navigator.language,
|
29 |
-
screenWidth: window.screen.width,
|
30 |
-
screenHeight: window.screen.height
|
31 |
-
})
|
32 |
-
"""
|
33 |
-
|
34 |
-
page.goto("about:blank")
|
35 |
-
device_info = page.evaluate(script)
|
36 |
-
browser.close()
|
37 |
-
|
38 |
-
return device_info
|
39 |
-
|
40 |
-
|
41 |
-
final_answer = FinalAnswerTool()
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
)
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
prompt_templates = yaml.safe_load(stream)
|
58 |
-
|
59 |
-
agent = CodeAgent(
|
60 |
-
model=model,
|
61 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
62 |
-
max_steps=6,
|
63 |
-
verbosity_level=1,
|
64 |
-
grammar=None,
|
65 |
-
planning_interval=None,
|
66 |
-
name=None,
|
67 |
-
description=None,
|
68 |
-
prompt_templates=prompt_templates
|
69 |
-
)
|
70 |
|
|
|
71 |
|
72 |
-
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from tools.final_answer import VisitWebpageTool
|
|
|
|
|
|
|
8 |
|
9 |
@tool
|
10 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
|
11 |
+
# Keep this format for the tool description / args description but feel free to modify the tool
|
12 |
+
"""A tool that does nothing yet
|
13 |
+
Args:
|
14 |
+
arg1: the first argument
|
15 |
+
arg2: the second argument
|
16 |
"""
|
17 |
+
return "What magic will you build ?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
@tool
|
20 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
21 |
+
"""A tool that fetches the current local time in a specified timezone.
|
22 |
+
Args:
|
23 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
24 |
+
"""
|
25 |
+
try:
|
26 |
+
# Create timezone object
|
27 |
+
tz = pytz.timezone(timezone)
|
28 |
+
# Get current time in that timezone
|
29 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
30 |
+
return f"The current local time in {timezone} is: {local_time}"
|
31 |
+
except Exception as e:
|
32 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
33 |
|
34 |
+
agent = CodeAgent(tools=[VisitWebpageTool()], model=HfApiModel())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")
|
37 |
|
|