Naveen671 commited on
Commit
7a80b44
·
verified ·
1 Parent(s): 396537e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -10
app.py CHANGED
@@ -1,34 +1,60 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool
 
 
 
2
  import yaml
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
 
6
- # Initialize the mandatory final answer tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  final_answer = FinalAnswerTool()
8
 
9
- # Set up the AI model connection
10
  model = HfApiModel(
11
  max_tokens=2096,
12
  temperature=0.5,
13
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
14
  )
15
 
16
- # Import the image generation tool from the Hugging Face Hub
17
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
18
 
19
- # Load the prompt templates
20
  with open("prompts.yaml", 'r') as stream:
21
  prompt_templates = yaml.safe_load(stream)
22
-
23
- # Create the agent and give it the correct tools
24
  agent = CodeAgent(
25
  model=model,
26
  # FIX: Add the 'image_generation_tool' to this list
27
  tools=[image_generation_tool, final_answer],
28
- max_steps=3,
29
  verbosity_level=1,
 
 
 
 
30
  prompt_templates=prompt_templates
31
  )
32
 
33
- # Launch the user interface
34
- 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 Gradio_UI import GradioUI
8
 
9
+ @tool
10
+ def my_custom_tool(arg1:str, arg2:int)-> str:
11
+ """A tool that does nothing yet
12
+ Args:
13
+ arg1: the first argument
14
+ arg2: the second argument
15
+ """
16
+ return "What magic will you build ?"
17
+
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.
21
+ Args:
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
+
33
  final_answer = FinalAnswerTool()
34
 
 
35
  model = HfApiModel(
36
  max_tokens=2096,
37
  temperature=0.5,
38
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
39
  )
40
 
41
+ # Import tool from Hub
42
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
43
 
 
44
  with open("prompts.yaml", 'r') as stream:
45
  prompt_templates = yaml.safe_load(stream)
46
+
 
47
  agent = CodeAgent(
48
  model=model,
49
  # FIX: Add the 'image_generation_tool' to this list
50
  tools=[image_generation_tool, final_answer],
51
+ max_steps=6,
52
  verbosity_level=1,
53
+ grammar=None,
54
+ planning_interval=None,
55
+ name=None,
56
+ description=None,
57
  prompt_templates=prompt_templates
58
  )
59
 
60
+ GradioUI(agent).launch()