Spaces:
Sleeping
Sleeping
Update of code
Browse files
app.py
CHANGED
@@ -25,27 +25,31 @@ def get_current_weather(arg1:str)-> str: #it's important to specify the return t
|
|
25 |
|
26 |
|
27 |
@tool
|
28 |
-
def get_weather_prediction(arg1:str, arg2:
|
29 |
"""A tool that will give you weather prediction
|
30 |
Args:
|
31 |
arg1: The location
|
32 |
-
arg2: weather prediction it must be part of this list ['clear','sunny','partly cloudy','cloudy','overcast','mist','patchy rain possible','light rain','moderate rain','heavy rain','thunderstorm','snow showers','blizzard','fog']
|
33 |
"""
|
|
|
|
|
|
|
|
|
34 |
url = f"https://wttr.in/{arg1}?format=j1"
|
35 |
response = requests.get(url)
|
36 |
expected_day = {}
|
37 |
if response.status_code == 200:
|
38 |
data = response.json()
|
39 |
-
for
|
40 |
-
for
|
41 |
-
for
|
42 |
-
if expected_weather.lower() in hourly["weatherDesc"][0]["value"].lower():
|
43 |
-
expected_day[expected_weather] = day
|
44 |
|
45 |
if len(expected_day):
|
46 |
return str(expected_day)
|
47 |
else:
|
48 |
-
return "
|
49 |
|
50 |
@tool
|
51 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -57,8 +61,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
57 |
# Create timezone object
|
58 |
tz = pytz.timezone(timezone)
|
59 |
# Get current time in that timezone
|
60 |
-
|
61 |
-
|
|
|
62 |
except Exception as e:
|
63 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
64 |
|
@@ -96,4 +101,4 @@ agent = CodeAgent(
|
|
96 |
)
|
97 |
|
98 |
|
99 |
-
GradioUI(agent).launch()
|
|
|
25 |
|
26 |
|
27 |
@tool
|
28 |
+
def get_weather_prediction(arg1:str, arg2:str) -> str:
|
29 |
"""A tool that will give you weather prediction
|
30 |
Args:
|
31 |
arg1: The location
|
32 |
+
arg2: weather prediction(s), it must be a comma separated list where all members must be part of this list ['clear','sunny','partly cloudy','cloudy','overcast','mist','patchy rain possible','light rain','moderate rain','heavy rain','thunderstorm','snow showers','blizzard','fog'].
|
33 |
"""
|
34 |
+
|
35 |
+
if isinstance(arg2, str):
|
36 |
+
arg2 = arg2.split(',')
|
37 |
+
|
38 |
url = f"https://wttr.in/{arg1}?format=j1"
|
39 |
response = requests.get(url)
|
40 |
expected_day = {}
|
41 |
if response.status_code == 200:
|
42 |
data = response.json()
|
43 |
+
for expected_weather in arg2:
|
44 |
+
for day in data["weather"]:
|
45 |
+
for hourly in day["hourly"]:
|
46 |
+
if expected_weather.lower() in hourly["weatherDesc"][0]["value"].lower().strip(' ') and expected_weather.lower() not in expected_day:
|
47 |
+
expected_day[expected_weather] = {'day' : day['date'], 'hour' : hourly['time']}
|
48 |
|
49 |
if len(expected_day):
|
50 |
return str(expected_day)
|
51 |
else:
|
52 |
+
return "It seems that the weather you are looking for is not in the forecast."
|
53 |
|
54 |
@tool
|
55 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
61 |
# Create timezone object
|
62 |
tz = pytz.timezone(timezone)
|
63 |
# Get current time in that timezone
|
64 |
+
local_day = datetime.datetime.now(tz).strftime("%Y-%m-%d")
|
65 |
+
local_time = datetime.datetime.now(tz).strftime("%H:%M:%S")
|
66 |
+
return f"The current local time in {timezone} is: day:{local_day} and time:{local_time}"
|
67 |
except Exception as e:
|
68 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
69 |
|
|
|
101 |
)
|
102 |
|
103 |
|
104 |
+
GradioUI(agent).launch()
|