Ludo7127 commited on
Commit
0cbdf4b
·
verified ·
1 Parent(s): e6ce27e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -43
app.py CHANGED
@@ -1,52 +1,20 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
- import os
3
- import datetime
4
  import pytz
5
- import yaml
6
- from tools.final_answer import FinalAnswerTool
7
- from Gradio_UI import GradioUI
8
 
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
 
 
 
 
 
 
 
 
11
  try:
12
  tz = pytz.timezone(timezone)
13
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
14
  return f"The current local time in {timezone} is: {local_time}"
15
  except Exception as e:
16
  return f"Error fetching time for timezone '{timezone}': {e}"
17
-
18
- final_answer = FinalAnswerTool()
19
-
20
- model = HfApiModel(
21
- max_tokens=2096,
22
- temperature=0.5,
23
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
24
- custom_role_conversions=None,
25
- )
26
-
27
- HF_TOKEN = os.getenv("HF_TOKEN")
28
- assert HF_TOKEN, "HF_TOKEN is not set in the environment."
29
-
30
- image_generation_tool = load_tool(
31
- "agents-course/text-to-image",
32
- trust_remote_code=True,
33
- hf_token=HF_TOKEN,
34
- )
35
-
36
- with open("prompts.yaml", "r") as f:
37
- prompt_templates = yaml.safe_load(f)
38
-
39
- agent = CodeAgent(
40
- model=model,
41
- tools=[
42
- final_answer,
43
- image_generation_tool,
44
- get_current_time_in_timezone,
45
- DuckDuckGoSearchTool(),
46
- ],
47
- max_steps=6,
48
- verbosity_level=2, # show tool traces
49
- prompt_templates=prompt_templates,
50
- )
51
-
52
- GradioUI(agent).launch()
 
1
+ from smolagents import tool
2
+ import datetime as dt
 
3
  import pytz
 
 
 
4
 
5
  @tool
6
  def get_current_time_in_timezone(timezone: str) -> str:
7
+ """Get the current local time for a given timezone.
8
+
9
+ Args:
10
+ timezone (str): IANA timezone like 'Europe/Brussels'.
11
+
12
+ Returns:
13
+ str: A formatted string with the local time or an error message.
14
+ """
15
  try:
16
  tz = pytz.timezone(timezone)
17
+ local_time = dt.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
18
  return f"The current local time in {timezone} is: {local_time}"
19
  except Exception as e:
20
  return f"Error fetching time for timezone '{timezone}': {e}"