SilviuMatei commited on
Commit
2a86392
·
verified ·
1 Parent(s): 504d406

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -60
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 get_device_info() -> str:
14
- """
15
- Opens a headless browser using Playwright and executes JavaScript to silently retrieve device information.
16
-
17
- Returns:
18
- str: A string containing device details such as user agent, platform, and screen resolution.
19
  """
20
- with playwright.sync_api.sync_playwright() as p:
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
- # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
44
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
45
-
46
- model = HfApiModel(
47
- max_tokens=2096,
48
- temperature=0.5,
49
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
50
- custom_role_conversions=None,
51
- )
52
-
53
- # Import tool from Hub
54
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
 
55
 
56
- with open("prompts.yaml", 'r') as stream:
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