Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
|
@@ -18,6 +19,52 @@ 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.
|
|
@@ -56,7 +103,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import pandas as pd
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def get_weather_tool(latitude:float, longitude:float)-> pd.Dataframe:
|
| 24 |
+
"""
|
| 25 |
+
A tool to get weather
|
| 26 |
+
"""
|
| 27 |
+
import openmeteo_requests
|
| 28 |
+
import requests_cache
|
| 29 |
+
from retry_requests import retry
|
| 30 |
+
|
| 31 |
+
# Setup the Open-Meteo API client with cache and retry on error
|
| 32 |
+
cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
|
| 33 |
+
retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2)
|
| 34 |
+
openmeteo = openmeteo_requests.Client(session = retry_session)
|
| 35 |
+
|
| 36 |
+
# Make sure all required weather variables are listed here
|
| 37 |
+
# The order of variables in hourly or daily is important to assign them correctly below
|
| 38 |
+
url = "https://api.open-meteo.com/v1/forecast"
|
| 39 |
+
params = {
|
| 40 |
+
"latitude": latitude,
|
| 41 |
+
"longitude": longitude,
|
| 42 |
+
"hourly": "temperature_2m",
|
| 43 |
+
}
|
| 44 |
+
responses = openmeteo.weather_api(url, params=params)
|
| 45 |
+
|
| 46 |
+
# Process first location. Add a for-loop for multiple locations or weather models
|
| 47 |
+
response = responses[0]
|
| 48 |
+
print(f"Coordinates: {response.Latitude()}°N {response.Longitude()}°E")
|
| 49 |
+
print(f"Elevation: {response.Elevation()} m asl")
|
| 50 |
+
print(f"Timezone difference to GMT+0: {response.UtcOffsetSeconds()}s")
|
| 51 |
+
|
| 52 |
+
# Process hourly data. The order of variables needs to be the same as requested.
|
| 53 |
+
hourly = response.Hourly()
|
| 54 |
+
hourly_temperature_2m = hourly.Variables(0).ValuesAsNumpy()
|
| 55 |
+
|
| 56 |
+
hourly_data = {"date": pd.date_range(
|
| 57 |
+
start = pd.to_datetime(hourly.Time(), unit = "s", utc = True),
|
| 58 |
+
end = pd.to_datetime(hourly.TimeEnd(), unit = "s", utc = True),
|
| 59 |
+
freq = pd.Timedelta(seconds = hourly.Interval()),
|
| 60 |
+
inclusive = "left"
|
| 61 |
+
)}
|
| 62 |
+
|
| 63 |
+
hourly_data["temperature_2m"] = hourly_temperature_2m
|
| 64 |
+
|
| 65 |
+
hourly_dataframe = pd.DataFrame(data = hourly_data)
|
| 66 |
+
return hourly_dataframe
|
| 67 |
+
|
| 68 |
@tool
|
| 69 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 70 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 103 |
|
| 104 |
agent = CodeAgent(
|
| 105 |
model=model,
|
| 106 |
+
tools=[final_answer,get_weather_tool], ## add your tools here (don't remove final answer)
|
| 107 |
max_steps=6,
|
| 108 |
verbosity_level=1,
|
| 109 |
grammar=None,
|