Spaces:
Sleeping
Sleeping
weather_yool
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -17,6 +18,48 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 17 |
arg2: the second argument
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 18 |
arg2: the second argument
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def check_weather(city: str, country: str) -> str:
|
| 24 |
+
"""A tool that checks the weather at a specified city.
|
| 25 |
+
Args:
|
| 26 |
+
city: The city for which to check the weather (e.g., 'Brezno').
|
| 27 |
+
country: The country code (e.g., 'SK' for Slovakia).
|
| 28 |
+
"""
|
| 29 |
+
# Replace with your actual API key
|
| 30 |
+
api_key = os.getenv("weather")
|
| 31 |
+
|
| 32 |
+
# Geocoding API URL
|
| 33 |
+
geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city},{country}&limit=1&appid={api_key}"
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
# Fetch the geocoding data
|
| 37 |
+
geo_response = requests.get(geo_url)
|
| 38 |
+
geo_data = geo_response.json()
|
| 39 |
+
|
| 40 |
+
if not geo_data:
|
| 41 |
+
return f"Error: Could not find location '{city}, {country}'."
|
| 42 |
+
|
| 43 |
+
# Extract latitude and longitude
|
| 44 |
+
lat = geo_data[0]['lat']
|
| 45 |
+
lon = geo_data[0]['lon']
|
| 46 |
+
|
| 47 |
+
# Weather API URL
|
| 48 |
+
weather_url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={api_key}"
|
| 49 |
+
|
| 50 |
+
# Fetch the weather data
|
| 51 |
+
weather_response = requests.get(weather_url)
|
| 52 |
+
weather_data = weather_response.json()
|
| 53 |
+
|
| 54 |
+
# Extract relevant weather information
|
| 55 |
+
current_weather = weather_data['current']
|
| 56 |
+
temperature = current_weather['temp']
|
| 57 |
+
weather_description = current_weather['weather'][0]['description']
|
| 58 |
+
|
| 59 |
+
return f"The current weather in {city}, {country} is {weather_description} with a temperature of {temperature}°C."
|
| 60 |
+
|
| 61 |
+
except Exception as e:
|
| 62 |
+
return f"Error fetching weather data: {str(e)}"
|
| 63 |
|
| 64 |
@tool
|
| 65 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 98 |
|
| 99 |
agent = CodeAgent(
|
| 100 |
model=model,
|
| 101 |
+
tools=[final_answer,check_weather,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 102 |
max_steps=6,
|
| 103 |
verbosity_level=1,
|
| 104 |
grammar=None,
|