yovanfowdar commited on
Commit
e5b8ef5
·
verified ·
1 Parent(s): 8484b2d

Update app.py

Browse files

Added my own tool , to get the OS works on Linux

Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -1,20 +1,22 @@
1
  # Yovan Fowdar
2
  # 27-02-2025
3
-
4
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
5
  import datetime
6
  import requests
7
  import pytz
8
  import yaml
 
 
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
12
 
 
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
16
  #Keep this format for the description / args / args description but feel free to modify the tool
17
- """A tool that does nothing yet
18
  Args:
19
  arg1: the first argument
20
  arg2: the second argument
@@ -36,11 +38,30 @@ def get_current_time_in_timezone(timezone: str) -> str:
36
  except Exception as e:
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  final_answer = FinalAnswerTool()
41
 
 
 
 
 
 
42
  # 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:
43
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
44
 
45
  model = HfApiModel(
46
  max_tokens=2096,
@@ -55,10 +76,10 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
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,
@@ -69,4 +90,4 @@ agent = CodeAgent(
69
  )
70
 
71
 
72
- GradioUI(agent).launch()
 
1
  # Yovan Fowdar
2
  # 27-02-2025
 
3
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
4
  import datetime
5
  import requests
6
  import pytz
7
  import yaml
8
+ import os
9
+ import platform
10
  from tools.final_answer import FinalAnswerTool
11
 
12
  from Gradio_UI import GradioUI
13
 
14
+
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
  @tool
17
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
18
  #Keep this format for the description / args / args description but feel free to modify the tool
19
+ """A tool that does nothing yet
20
  Args:
21
  arg1: the first argument
22
  arg2: the second argument
 
38
  except Exception as e:
39
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
 
41
+ @tool
42
+ #mytool works on linux ubuntu
43
+ def get_os() -> str:
44
+ """
45
+ Retrieves the name and version of the operating system.
46
+
47
+ Returns:
48
+ str: A string representing the operating system details.
49
+ """
50
+ try:
51
+ result = platform.platform()
52
+ return result
53
+ except:
54
+ return "Sorry, cannot get the OS"
55
 
56
  final_answer = FinalAnswerTool()
57
 
58
+
59
+
60
+
61
+
62
+
63
  # 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:
64
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
65
 
66
  model = HfApiModel(
67
  max_tokens=2096,
 
76
 
77
  with open("prompts.yaml", 'r') as stream:
78
  prompt_templates = yaml.safe_load(stream)
79
+
80
  agent = CodeAgent(
81
  model=model,
82
+ tools=[final_answer, get_os, ], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
 
90
  )
91
 
92
 
93
+ GradioUI(agent).launch(server_name='0.0.0.0')