Nilaksh2004 commited on
Commit
d3904a6
·
verified ·
1 Parent(s): 7cf04b6

reverted back to oringinal

Browse files
Files changed (1) hide show
  1. app.py +16 -71
app.py CHANGED
@@ -1,66 +1,20 @@
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 Gradio_UI import GradioUI
8
-
9
  @tool
10
- def unit_converter(value: float, from_unit: str, to_unit: str) -> str:
11
- """A tool that converts a value between common units of length, weight, or temperature.
 
12
  Args:
13
- value: The numeric value to convert.
14
- from_unit: The unit to convert from (e.g. 'km', 'miles', 'kg', 'lb', 'celsius', 'fahrenheit').
15
- to_unit: The unit to convert to (e.g. 'km', 'miles', 'kg', 'lb', 'celsius', 'fahrenheit').
16
  """
17
- try:
18
- from_unit = from_unit.strip().lower()
19
- to_unit = to_unit.strip().lower()
20
-
21
- # Length (base unit: meters)
22
- length = {
23
- "m": 1, "meter": 1, "meters": 1,
24
- "km": 1000, "kilometer": 1000, "kilometers": 1000,
25
- "cm": 0.01, "centimeter": 0.01, "centimeters": 0.01,
26
- "mile": 1609.34, "miles": 1609.34,
27
- "yard": 0.9144, "yards": 0.9144,
28
- "ft": 0.3048, "feet": 0.3048, "foot": 0.3048,
29
- "in": 0.0254, "inch": 0.0254, "inches": 0.0254,
30
- }
31
- # Weight (base unit: kilograms)
32
- weight = {
33
- "kg": 1, "kilogram": 1, "kilograms": 1,
34
- "g": 0.001, "gram": 0.001, "grams": 0.001,
35
- "lb": 0.453592, "lbs": 0.453592, "pound": 0.453592, "pounds": 0.453592,
36
- "oz": 0.0283495, "ounce": 0.0283495, "ounces": 0.0283495,
37
- }
38
-
39
- if from_unit in length and to_unit in length:
40
- result = value * length[from_unit] / length[to_unit]
41
- return f"{value} {from_unit} = {round(result, 4)} {to_unit}"
42
-
43
- if from_unit in weight and to_unit in weight:
44
- result = value * weight[from_unit] / weight[to_unit]
45
- return f"{value} {from_unit} = {round(result, 4)} {to_unit}"
46
-
47
- if from_unit in ("celsius", "c") and to_unit in ("fahrenheit", "f"):
48
- result = (value * 9/5) + 32
49
- return f"{value}°C = {round(result, 2)}°F"
50
- if from_unit in ("fahrenheit", "f") and to_unit in ("celsius", "c"):
51
- result = (value - 32) * 5/9
52
- return f"{value}°F = {round(result, 2)}°C"
53
- if from_unit in ("celsius", "c") and to_unit in ("kelvin", "k"):
54
- result = value + 273.15
55
- return f"{value}°C = {round(result, 2)}K"
56
- if from_unit in ("kelvin", "k") and to_unit in ("celsius", "c"):
57
- result = value - 273.15
58
- return f"{value}K = {round(result, 2)}°C"
59
-
60
- return f"Cannot convert from '{from_unit}' to '{to_unit}'. Supported: length (m, km, cm, mile, yard, ft, in), weight (kg, g, lb, oz), temperature (celsius, fahrenheit, kelvin)."
61
- except Exception as e:
62
- return f"Error converting units: {str(e)}"
63
-
64
  @tool
65
  def get_current_time_in_timezone(timezone: str) -> str:
66
  """A tool that fetches the current local time in a specified timezone.
@@ -68,39 +22,30 @@ def get_current_time_in_timezone(timezone: str) -> str:
68
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
69
  """
70
  try:
 
71
  tz = pytz.timezone(timezone)
 
72
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
73
  return f"The current local time in {timezone} is: {local_time}"
74
  except Exception as e:
75
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
76
-
77
  final_answer = FinalAnswerTool()
78
- web_search = DuckDuckGoSearchTool()
79
-
80
  # 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:
81
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
82
  model = HfApiModel(
83
- max_tokens=2096,
84
- temperature=0.5,
85
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
86
- custom_role_conversions=None,
87
  )
88
-
89
  # Import tool from Hub
90
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
91
-
92
  with open("prompts.yaml", 'r') as stream:
93
  prompt_templates = yaml.safe_load(stream)
94
-
95
  agent = CodeAgent(
96
  model=model,
97
- tools=[
98
- final_answer,
99
- web_search,
100
- get_current_time_in_timezone,
101
- image_generation_tool,
102
- unit_converter,
103
- ], ## add your tools here (don't remove final answer)
104
  max_steps=6,
105
  verbosity_level=1,
106
  grammar=None,
 
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 Gradio_UI import GradioUI
8
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
9
  @tool
10
+ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
11
+ #Keep this format for the description / args / 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
  @tool
19
  def get_current_time_in_timezone(timezone: str) -> str:
20
  """A tool that fetches the current local time in a specified timezone.
 
22
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
23
  """
24
  try:
25
+ # Create timezone object
26
  tz = pytz.timezone(timezone)
27
+ # Get current time in that timezone
28
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
29
  return f"The current local time in {timezone} is: {local_time}"
30
  except Exception as e:
31
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
32
  final_answer = FinalAnswerTool()
 
 
33
  # 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:
34
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
35
  model = HfApiModel(
36
+ max_tokens=2096,
37
+ temperature=0.5,
38
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
39
+ custom_role_conversions=None,
40
  )
 
41
  # Import tool from Hub
42
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
43
  with open("prompts.yaml", 'r') as stream:
44
  prompt_templates = yaml.safe_load(stream)
45
+
46
  agent = CodeAgent(
47
  model=model,
48
+ tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
 
 
 
49
  max_steps=6,
50
  verbosity_level=1,
51
  grammar=None,