sarjan109 commited on
Commit
4bd043e
·
verified ·
1 Parent(s): ff0650d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -8,35 +8,48 @@ from Gradio_UI import GradioUI
8
 
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
- """Fetch current time in a timezone"""
 
 
 
 
 
 
 
 
12
  try:
13
  tz = pytz.timezone(timezone)
14
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
15
  return f"The current local time in {timezone} is: {local_time}"
16
  except Exception as e:
17
- return str(e)
18
 
19
 
 
20
  final_answer = FinalAnswerTool()
21
 
22
 
 
23
  model = HfApiModel(
24
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
25
  max_tokens=2096,
26
- temperature=0.5
27
  )
28
 
29
 
 
30
  image_generation_tool = load_tool(
31
  "agents-course/text-to-image",
32
  trust_remote_code=True
33
  )
34
 
35
 
 
36
  with open("prompts.yaml", "r") as stream:
37
  prompt_templates = yaml.safe_load(stream)
38
 
39
 
 
40
  agent = CodeAgent(
41
  model=model,
42
  tools=[
@@ -47,8 +60,13 @@ agent = CodeAgent(
47
  ],
48
  max_steps=6,
49
  verbosity_level=2,
 
 
 
 
50
  prompt_templates=prompt_templates
51
  )
52
 
53
 
 
54
  GradioUI(agent).launch()
 
8
 
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
+ """
12
+ Get the current local time in a specified timezone.
13
+
14
+ Args:
15
+ timezone (str): A valid timezone string such as 'Asia/Kolkata' or 'America/New_York'.
16
+
17
+ Returns:
18
+ str: The current local time in the specified timezone.
19
+ """
20
  try:
21
  tz = pytz.timezone(timezone)
22
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
23
  return f"The current local time in {timezone} is: {local_time}"
24
  except Exception as e:
25
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
26
 
27
 
28
+ # Final answer tool (mandatory for agent)
29
  final_answer = FinalAnswerTool()
30
 
31
 
32
+ # LLM model for agent reasoning
33
  model = HfApiModel(
34
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
35
  max_tokens=2096,
36
+ temperature=0.5,
37
  )
38
 
39
 
40
+ # Image generation tool from Hugging Face Agents course
41
  image_generation_tool = load_tool(
42
  "agents-course/text-to-image",
43
  trust_remote_code=True
44
  )
45
 
46
 
47
+ # Load prompt templates
48
  with open("prompts.yaml", "r") as stream:
49
  prompt_templates = yaml.safe_load(stream)
50
 
51
 
52
+ # Create agent
53
  agent = CodeAgent(
54
  model=model,
55
  tools=[
 
60
  ],
61
  max_steps=6,
62
  verbosity_level=2,
63
+ grammar=None,
64
+ planning_interval=None,
65
+ name="MultiTool Agent",
66
+ description="Agent that can search the web, generate images, and fetch timezone information.",
67
  prompt_templates=prompt_templates
68
  )
69
 
70
 
71
+ # Launch Gradio UI
72
  GradioUI(agent).launch()