Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,48 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def get_today_average_temperature(latitude:float, longitude:float)-> float:
|
| 23 |
+
"""A tool that fetches today average temperature for given latitude and longitude
|
| 24 |
+
Args:
|
| 25 |
+
latitude: A coordinate representing latitude
|
| 26 |
+
longitude: A coordinate representing longitude
|
| 27 |
+
"""
|
| 28 |
+
# Setup the Open-Meteo API client with cache and retry on error
|
| 29 |
+
cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
|
| 30 |
+
retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2)
|
| 31 |
+
openmeteo = openmeteo_requests.Client(session = retry_session)
|
| 32 |
+
|
| 33 |
+
# Make sure all required weather variables are listed here
|
| 34 |
+
# The order of variables in hourly or daily is important to assign them correctly below
|
| 35 |
+
url = "https://api.open-meteo.com/v1/forecast"
|
| 36 |
+
params = {
|
| 37 |
+
"latitude": latitude,
|
| 38 |
+
"longitude": longitude,
|
| 39 |
+
"hourly": "temperature_2m",
|
| 40 |
+
"models": "ecmwf_ifs025"
|
| 41 |
+
}
|
| 42 |
+
responses = openmeteo.weather_api(url, params=params)
|
| 43 |
+
|
| 44 |
+
# Process first location. Add a for-loop for multiple locations or weather models
|
| 45 |
+
response = responses[0]
|
| 46 |
+
|
| 47 |
+
# Process hourly data. The order of variables needs to be the same as requested.
|
| 48 |
+
hourly = response.Hourly()
|
| 49 |
+
hourly_temperature_2m = hourly.Variables(0).ValuesAsNumpy()
|
| 50 |
+
|
| 51 |
+
hourly_data = {"date": pd.date_range(
|
| 52 |
+
start = pd.to_datetime(hourly.Time(), unit = "s", utc = True),
|
| 53 |
+
end = pd.to_datetime(hourly.TimeEnd(), unit = "s", utc = True),
|
| 54 |
+
freq = pd.Timedelta(seconds = hourly.Interval()),
|
| 55 |
+
inclusive = "left"
|
| 56 |
+
)}
|
| 57 |
+
|
| 58 |
+
hourly_data["temperature_2m"] = hourly_temperature_2m
|
| 59 |
+
|
| 60 |
+
hourly_dataframe = pd.DataFrame(data = hourly_data)
|
| 61 |
+
return hourly_dataframe["temperature_2m"].mean()
|
| 62 |
+
|
| 63 |
@tool
|
| 64 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 65 |
"""A tool that fetches the current local time in a specified timezone.
|