DragonProgrammer commited on
Commit
2d0d963
·
verified ·
1 Parent(s): c493145

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -5,12 +5,10 @@ import pandas as pd
5
  import datetime
6
  import requests
7
  import pytz
8
- import yaml
9
  from transformers import HfAgent
10
  from bs4 import BeautifulSoup
11
  import math
12
  import re
13
- import inspect
14
 
15
 
16
  # (Keep Constants as is)
@@ -19,17 +17,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
 
20
  # --- Tool Definitions ---
21
  def get_current_time_in_timezone(timezone: str) -> str:
22
- """A tool that fetches the current local time in a specified timezone.
23
  Args:
24
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
25
  """
 
26
  try:
27
- # Create timezone object
28
  tz = pytz.timezone(timezone)
29
- # Get current time in that timezone
30
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
31
  return f"The current local time in {timezone} is: {local_time}"
 
 
 
32
  except Exception as e:
 
33
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
34
 
35
  def web_search(query: str) -> str:
 
5
  import datetime
6
  import requests
7
  import pytz
 
8
  from transformers import HfAgent
9
  from bs4 import BeautifulSoup
10
  import math
11
  import re
 
12
 
13
 
14
  # (Keep Constants as is)
 
17
 
18
  # --- Tool Definitions ---
19
  def get_current_time_in_timezone(timezone: str) -> str:
20
+ """Fetches the current local time in a specified IANA timezone (e.g., 'America/New_York', 'Europe/London', 'UTC').
21
  Args:
22
+ timezone (str): A string representing a valid IANA timezone name.
23
  """
24
+ print(f"--- Tool: Executing get_current_time_in_timezone for: {timezone} ---")
25
  try:
 
26
  tz = pytz.timezone(timezone)
27
+ # Added %Z (timezone name) and %z (UTC offset)
28
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S %Z%z")
29
  return f"The current local time in {timezone} is: {local_time}"
30
+ except pytz.exceptions.UnknownTimeZoneError:
31
+ print(f"Error: Unknown timezone '{timezone}'")
32
+ return f"Error: Unknown timezone '{timezone}'. Please use a valid IANA timezone name (e.g., 'America/Denver', 'UTC')."
33
  except Exception as e:
34
+ print(f"Error fetching time for timezone '{timezone}': {str(e)}")
35
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
36
 
37
  def web_search(query: str) -> str: